I have written a rest service to encrypt and decrypt URL.
Encryption code:
@GET
@Produces("application/json")
@Path("/encrypt/")
public Response encryptWithQuery(@QueryParam("plainString") String plainString)
throws JSONException {
Response response = new Response();
AesUtil util = new AesUtil(KEY_SIZE, ITERATION_COUNT);
response = util.encrypt(SALT, IV, PASSPHRASE, plainString);
return response;
}
Decryption code:
@GET
@Produces("application/json")
@Path("/decryptWP/")
public Response decryptWithQuery(@QueryParam("encryptString") String encryptString)
throws JSONException {
Response response = new Response();
AesUtil util = new AesUtil(KEY_SIZE, ITERATION_COUNT);
response = util.decrypt(SALT, IV, PASSPHRASE, encryptString);
return response;
}
When i call my encrypt rest service i get the encrypted string
url for encryption
http://localhost:9080/kttafm/keybank/encrypt?plainString=http://localhost:9080/kttafm/master.jsp?abc=zyx
But when i call the decryption rest service i get below exception
javax.crypto.BadPaddingException: Given final block not properly padded
But if i move from @Queryparam tp @path param, The decryption works fine,
The decrypt method which works fine and decrypts the encrypted string is
@GET
@Produces("application/json")
@Path("/decrypt/{encryptString}")
public Response decrypt(@PathParam("encryptString") String encryptString)
throws JSONException {
Response response = new Response();
AesUtil util = new AesUtil(KEY_SIZE, ITERATION_COUNT);
response = util.decrypt(SALT, IV, PASSPHRASE, encryptString);
return response;
}
What am i missing?