Hello,
I am using AES Encryption method to encrypt the parameter values of a URL. Basically, I am taking the URL, splitting it using "&" to get the parameter/value pair, then splitting it again to the individual value and passing it to encrypt method.
public static String encryptParameters(byte[] buffer){
String fileLocation = "D://AESkey.txt";
SecretKeySpec key = GenerateAesKey.readKey(fileLocation);
Cipher cipher = null;
String encryptedValue = new String();
byte[] byteCipherText = null;
try{
cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byteCipherText = cipher.doFinal(buffer);
encryptedValue = new BASE64Encoder().encode(byteCipherText);
} catch (Exception e){
e.printStackTrace();
}
return encryptedValue ;
}
However, my problem is that the value after encryption contains characters like "==" or "/" which would make the URL corrupt. I am using Base64 Encoder to convert byte [] (that's returned from the cipher encryption) into String.
How can I get around this issue?? Is there something other than Base64 that I should use?? PLease note that I do have to decrypt the values in my servlet, so I would need to use the same method there to decode as well.
Thanks in advance for your advice.
J