I have a problem generating the same ciphertext in JavaScript as provided in a third party PHP server. The server side uses a simple one-liner to generate a key, but I can't find a way to do the same in my JavaScript client.
I decided to use the CryptoJS library, from other SO answers , and I did generate a ciphertext but it was different that the one from a PHP server.
PHP encryption:
echo openssl_encrypt("5905","AES-256-CBC","FbcCY2yCFBwVCUE9R+6kJ4fAL4BJxxjdRcqy5rHVLwU=",NULL,"e16ce913a20dadb8");
// phgygAJB3GA0sa4D9k/d8A==
I have tried several solutions from Stack Overflow which failed to create the same ciphertext.
Also, the parameter "AES-256-CBC" in the PHP one-liner bothers me: I know what AES is, but I have no idea what those 256 or CBC parts are, and I don't know where to set those on the CryptoJS side.
My current attempt:
var key = 'FbcCY2yCFBwVCUE9R+6kJ4fAL4BJxxjdRcqy5rHVLwU=';
var iv = 'e16ce913a20dadb8';
var encrypted = CryptoJS.AES.encrypt("5905", CryptoJS.enc.Hex.parse(key), { iv: CryptoJS.enc.Hex.parse(iv) });
var r1 = encrypted.ciphertext.toString(); // def44f8822cfb3f317a3c5b67182b437
var r2 = CryptoJS.enc.Base64.stringify(encrypted.ciphertext) // 3vRPiCLPs/MXo8W2cYK0Nw==
My guess is that I am missing "256" and "CBC" parameters somewhere in JavaScript.