Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

AES Encryption used for URL

843811Oct 23 2009 — edited Oct 23 2009
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 20 2009
Added on Oct 23 2009
1 comment
289 views