I have some logic for encrypting an API key in PHP and i want to do exactly the same in javascript, with the same results
$api_key = '7#4VBg7ZN3vGZPL4&r3Ow^k4#s2$Q9&NP!ofWJXPP*Tgg05Y05' . date('Ymd');
$encrypt_method = 'AES-256-CBC';
$salt_key = '0Ao10GYe^4EfBYMp';
$salt_iv = 'uV6h%Vl^$u1$vo4^';
base64_encode(openssl_encrypt($api_key, $encrypt_method, $salt_key, 0, $salt_iv));
I tried this code in js, but it doesnt give the same result
const CryptoJS = require('crypto-js');
const api_key = '7#4VBg7ZN3vGZPL4&r3Ow^k4#s2$Q9&NP!ofWJXPP*Tgg05Y05' + new Date().toISOString().slice(0, 10).replace(/-/g, '');
const salt_key = '0Ao10GYe^4EfBYMp';
const salt_iv = 'uV6h%Vl^$u1$vo4^';
const encrypted = CryptoJS.AES.encrypt(api_key, salt_key, {
iv: CryptoJS.enc.Utf8.p
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
const base64Encrypted = encrypted.toString();