I have a problem with crypto in nodejs, from PHP I have encrypted text and I would like to decrypt it from node js, but I get an error when trying to decrypt the text:
wrong final block length.
Attached code of encryption in php 7.0.
public static function encrypt($string) {
if($string == "" || $string == NULL){
return "";
}
return openssl_encrypt($string, 'AES-128-ECB', 'mypasswordinstrig');
}
Node v16.15 decryption code (In this function I have problems)
const crypto = require('crypto');
const CRYPT_ALGORITHM = 'aes-128-ecb';
module.exports.decrypt = (dataEncoded) => {
const key = crypto.scryptSync('mypasswordinstrig', '', 16);
const decipher = crypto.createDecipheriv(CRYPT_ALGORITHM, key, null);
let decrypted = decipher.update(dataEncoded);
decrypted = Buffer.concat([decrypted, decipher.final('hex')]);
return decrypted.toString();
};