Problem Encrypting URL using AES
I am successfully encrypting a URL from my client servlet and my serverside servlet handles the request. The code is below.
My problem is that the decrypted URL is not the "id=101&item=22&conf=12234" I am expecting -- in fact, the encrypted part of the URL is changing each time (not what I'd expect because I'm using the same passphrase). I need help understanding AES encryption and possibly an example using a passphrases would be appreciated.
Client servlet code:
String passphrase ="passwordpassword";
byte[] raw = passphrase.getBytes();
SecretKeySpec skeySpec =new SecretKeySpec(raw,"AES");
// Instantiate the cipher
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
String query ="id=101&item=22&conf=12234";
byte[] encrypted = cipher.doFinal(query.getBytes());
String encoded = encodeURL(encrypted.toString());
//GET
response.sendRedirect(DEFAULT_SERVER +"?data=" + encoded);
Serverside servlet code:
String passphrase ="passwordpassword";
byte[] raw = passphrase.getBytes();
SecretKeySpec skeySpec =new SecretKeySpec(raw,"AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(decodedData.getBytes());
byte[] original = cipher.doFinal(decrypted);
String text =new String(original,"utf-8");
out.println(text);

