Crypto.js decrypts the key and iv (vector) in byte arrays

I need to decrypt some strings that are encrypted by AES.

Encrypted string example: 129212143036071008133136215105140171136216244116

I have a key, and vector (iv) is provided to me in byte array format:

Key: [123, 217, 20, 11, 24, 26, 85, 45, 114, 184, 27, 162, 37, 115, 222, 209, 241, 24, 175, 144, 175, 53, 196, 29 , 24, 23, 17, 218, 131, 226, 53, 209]

Vector (iv): [146, 66, 191, 151, 23, 3, 113, 119, 231, 131, 133, 112, 79, 32, 114, 136]

I can decrypt the string and get:

Valid output: testtest

I am trying to use Crypto.js, but I cannot find a way to use the provided key and vector. I cannot find a way to convert byte arrays to hex.

var encrypted = '129212143036071008133136215105140171136216244116';
var key = CryptoJS.enc.Hex.parse([ 123, 217, 20, 11, 24, 26, 85, 45, 114, 184, 27, 162, 37, 115, 222, 209, 241, 24, 175, 144, 175, 53, 196, 29, 24, 23, 17, 218, 131, 226, 53, 209 ]);
var iv  = CryptoJS.enc.Hex.parse([ 146, 66, 191, 151, 23, 3, 113, 119, 231, 131, 133, 112, 79, 32, 114, 136 ]);

var decrypted = CryptoJS.AES.decrypt(encrypted, key, { iv: iv });

console.log('Output: '+decrypted.toString(CryptoJS.enc.Utf8)); //Should be "testtest"

, - , Crypto.js js-.

,

+4
2

, . aes.js, , key iv , . :

//var encrypted = '129212143036071008133136215105140171136216244116';

var key = CryptoJS.enc.Hex.parse(CryptoJS.lib.ByteArray([123, 217, 20, 11, 24, 26, 85, 45, 114, 184, 27, 162, 37, 115, 222, 209, 241, 24, 175, 144, 175, 53, 196, 29, 24, 23, 17, 218, 131, 226, 53, 209]));
var iv = CryptoJS.enc.Hex.parse(CryptoJS.lib.ByteArray([146, 66, 191, 151, 23, 3, 113, 119, 231, 131, 133, 112, 79, 32, 114, 136]));

var  message = 'testest'
var encrypted =  CryptoJS.AES.encrypt(message, key, {
  'iv': iv
});


var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
  'iv': iv
});
document.write('Output: ' + decrypted.toString(CryptoJS.enc.Utf8)); //Should be "testtest"
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/pad-nopadding-min.js"></script>
<script src="https://greasyfork.org/scripts/6696-cryptojs-lib-bytearray/code/CryptoJSlibByteArray.js"></script>
Hide result
+1
+1

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


All Articles