Encrypt/Decrypt aes256cbc in Nodejs

I’m working on a porject where I need develop a Encrypt/Decrypt string in nodejs.

I receive the string the next format: pTS3JQzTxrSbd+cLESXHpg==

this string is generate from this page: https://encode-decode.com/aes-256-cbc-encrypt-online/

and use the aes-256-cbc standard

the code that i implemented is the next:

var CryptoJS = require("crypto-js");

var key = 'TEST_KEY';
var text = 'pTS3JQzTxrSbd+cLESXHpg==';

function decript(text, key) {
    return CryptoJS.AES.decrypt(text.trim(), key);

console.log(decript(text, key).toString(CryptoJS.enc.Utf8));

But i always get an empty response.

could you say to me what is the issue?

thanks a lot!


As the documentation explains and I just answered yesterday, CryptoJS.AES when given a ‘key’ that is a string treats it as a password and uses password-based key derivation compatible with openssl enc. That is different from and incompatible with what your linked website does, which is not clearly stated, but based on the list of cipher names is almost certainly internally calling OpenSSL’s ‘EVP’ interface, which means among other things that if you specify a key too short for the algorithm, as you did, it uses whatever happens to be adjacent in memory, which apparently was zero-value bytes (not unusual for programs run on operating systems newer than about 1980), and it either uses the default IV of zero bytes or similarly sets it to something that is zero bytes. And for CBC it uses PKCS5/7 padding, which is compatible with CryptoJS (and most other things). Therefore:

const CryptoJS = require('crypto-js');
var key = CryptoJS.enc.Latin1.parse("TEST_KEY"+"")
var iv = CryptoJS.enc.Latin1.parse("")
var ctx = CryptoJS.enc.Base64.parse("pTS3JQzTxrSbd+cLESXHpg==")
var enc = CryptoJS.lib.CipherParams.create({ciphertext:ctx})
console.log( CryptoJS.AES.decrypt (enc,key,{iv:iv}) .toString(CryptoJS.enc.Utf8) )
Test text