I'm using below code to encrypt data using CryptoJS
export const encryptData = (data) => {
let key = CryptoJS.enc.Utf8.parse(api.encryption.Key);
let iv = {
keySize: 128 / 8,
iv: CryptoJS.enc.Utf8.parse(api.encryption.IV),
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
};
return encodeURIComponent(CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(data), key, iv));
}
And for decrypting the data i used below code. But data is not getting decrypted. However encrypt is working fine.
export const decryptData = (data) => {
let key = CryptoJS.enc.Utf8.parse(api.encryption.Key);
let iv = {
keySize: 128 / 8,
iv: CryptoJS.enc.Utf8.parse(api.encryption.IV),
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
};
return decodeURIComponent(CryptoJS.AES.decrypt(CryptoJS.enc.Utf8.parse(data), key, iv));
}
Any idea what I am doing wrong while decrypting?