Crypto-js returns different values ​​every time it starts when using AES

I am trying to encrypt something using crypto-js and use encryption like AES.

The problem I am facing is that my encrypted value is different every time it is encrypted.

In this simple example, I run the same encryption 5 times, and I get 5 different results. Wtf going on here?

task.js

var AES = require('crypto-js/aes');
var key = "abc123";
var secret = "encryptThisWord";

console.log(AES.encrypt(secret, key).toString());
console.log(AES.encrypt(secret, key).toString());
console.log(AES.encrypt(secret, key).toString());
console.log(AES.encrypt(secret, key).toString());
console.log(AES.encrypt(secret, key).toString());

enter image description here

+4
source share
1 answer

Check the contents AES.encrypt(secret, key)- this is an object with a number of fields, ivand of saltparticular interest ( jsFiddle ).

, AES.encrypt, -js IV (, ). IV , , , , .

(, ) , Base64 , IV ? , toString() ecnryption " OpenSSL ", Base64("Salted__" + salt + ciphertext), "Salted__" - , , , Base64.

+6

Source: https://habr.com/ru/post/1546327/


All Articles