I use following code in JS to encrypt my data:
const crypto = require('crypto');
const IV_LENGTH = 16; // For AES, this is always 16
export function encrypt(text, key) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', new Buffer(key), iv);
let encrypted = cipher.update(text);
encrypted = Buffer.concat([encrypted, cipher.final()]);
return iv.toString('hex') + ':' + encrypted.toString('hex');
}
I have tried to decrypt it in PHP (with pack('H*',.) etc but I can't find a solution to decode it in PHP. All the time I get the error that the IV is to long because I am not able to transform it back in PHP.
Do you have an idea how I can decrypt it in PHP?
Thank you very much and I wish a nice weekend!