Hi All,
Here I write a program for Text Encryption using BASE64Encoder concept, Also I used the String conversion, ASCII conversion and Byte conversion finally three levels of BASE64Encoder concept. It's a highly secure encryption technique.
/**
*
* @author BALAMURUGAN M.R
*/
import java.util.Scanner;
import java.util.StringTokenizer;
import sun.misc.BASE64Encoder;
public class SkiEncryption {
static String finalEncode = "", finalDecode = "";
//Method for getting value from user
public static void main(String arg[]) {
System.out.println("SKiTECH Encryption Technique");
System.out.println("Please enter any text for Encryption ");
Scanner str1 = new Scanner(System.in);
String name = str1.nextLine();
String valToEncrypt = name, encryptedValue = "";
encryptedValue = encryption(valToEncrypt);
System.out.println("After Encryption value \n " + encryptedValue);
}
//Method for converting String to ASCII value format
public static String encryption(String valToEncrypt) {
String encryptedValue = stringToASCII(valToEncrypt);
return encryptedValue;
}
//Method for converting String to ASCII value format
private static String stringToASCII(String valToEncrypt) {
String val = "", encrypt = "";
for (int i = 0; i < valToEncrypt.length(); ++i) {
char c = valToEncrypt.charAt(i);
int j = (int) c;
String byteval = asciiToByte(j);
val = val + byteval;
}
encrypt = encode(val);
return encrypt;
}
//Method for THREE LEVEL OF BASE64Encoder CONVERSION FOR BYTE CODES
public static String encode(String val) {
val = val.trim().toLowerCase();
try {
BASE64Encoder encoder = new BASE64Encoder();
String firstEncode = new String(encoder.encodeBuffer(val.getBytes())); // 1st level encryption for byte code
String secEncode = new String(encoder.encodeBuffer(firstEncode.getBytes())); //2nd level encryption for byte code
finalEncode = encoder.encodeBuffer(secEncode.getBytes()); // 3rd level encryption for byte code
} catch (Exception e) {
System.out.println("Encryprtion error : " + e);
}
return finalEncode;
}
//Method for converting ASCII to BYTE value format
public static String asciiToByte(int acii) {
String by = Integer.toBinaryString(acii);
return (by + ",");
}
}
output:
~~~~~~
SKiTECH Encryprtion TechniquePlease enter any text for Encryption
krishna
After Encryption value
VFZSRmQwMVVRWGhOVTNkNFRWUkZkMDFFUlhkTVJFVjRUVVJGZDAxRVJYTk5WRVY0VFVSQmVFMVRk
M2hOVkVGNFRVUkJkMHhFUlhoTg0KUkVWNFRWUkJjMDFVUlhkTlJFRjNUVk4zUFEwSw0K
No comments:
Post a Comment