Every time New Encrypted string Generate using AES
Author: AkibDeraiya123Created Feb 23, 2018Updated May 18, 2026
Hello,
I'm using crypto-js library with Node.js Encryption/Decryption `(String/ Stringify object).
Issue is that when i try to Encrypt any string then every moment i get different different encrypted strings But when i Decrypt this all the strings then i got the same plain text Which i use for encrypt.
I want to do like same Encrypted string every moment.
Here my node and npm version
Node:- v8.9.1
NPM:- 5.5.1My code is like this,
var CryptoJS = require("crypto-js");
const Key = '39067A6F8088F81E9C2BB5D46A8C0F60';
const text = JSON.stringify({Key1: 'value1', key2:'key2'});
// Encrypt
var ciphertext = CryptoJS.AES.encrypt(text, Key);
console.log(ciphertext); // Here i got different different strings every moment for same plain text
// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext.toString(), Key);
var plaintext = bytes.toString(CryptoJS.enc.Utf8);
console.log(JSON.parse(plaintext)); // Print like { Key1: 'value1', key2: 'key2' }I want to do like that every moment i got same encrypted string for same plain text.
Please help me i'm in stuck.
Thank you in advance :)
Source: brix/crypto-js