I have an encrypted string created in NodeJS using crypto
NodeJS:
const crypto = require('crypto');
const key = Buffer.from(SECRET_KEY, 'base64');
encrypt(text) {
const iv = crypto.randomBytes(16);
let cipher = crypto.createCipheriv(
'AES-128-CBC', key, iv);
let encrypted = cipher.update(text);
encrypted = Buffer.concat([iv, encrypted, cipher.final()]);
return encrypted.toString('hex');
}
It is working perfectly and I can't change the NodeJS. Then, I try to decrypt it using React crypto-js, but it returns an empty string.
var CryptoJS = require("crypto-js");
const KEY = SECRET_KEY;
export const decrypt = (text) => {
var bytes = CryptoJS.AES.decrypt(text, KEY);
return bytes.toString(CryptoJS.enc.Hex);
}
Am I missing any configuration in React?
Thanks