I tried to encrypt the JSON in javascript as shown in below and it is encrypted. In below "obj" is my JSON data and i don't know why "ency_key", I followed this from some where in google and they passed String like that.
var obj1 = CryptoJS.AES.encrypt(obj,'ency_key').toString();
$.ajax({
url: "web/enyDcyData",
"type": "POST",
async:true,
data:{
json:obj1,
}
but am unable to decryption the data in java, I tried like below in java. am getting javax.crypto.BadPaddingException: Given final block not properly padded exception at "doFinal(base64Decode(ency_data));" where I done mistake, please help me to solve this problem.
public static String decrypt(String ency_data)
SecretKeyFactory keyFac = SecretKeyFactory.getInstance(one);
SecretKey seckey = keyFac.generateSecret(new PBEKeySpec(two));
Cipher cipher = Cipher.getInstance(one);
pbeCipher.init(Cipher.DECRYPT_MODE, seckey , new PBEParameterSpec(SALT, 20));
byte[] res = cipher.doFinal(base64Decode(ency_data));
String decryptedValue = new String(res,"UTF-8");
}
private static byte[] base64Decode(String ency_data) throws IOException {
return new BASE64Decoder().decodeBuffer(ency_data);
}