'TypeError: Cannot read property 'length' of undefined in cryptoJS
I am trying to encrypt data in cryptoJS in nodeJS but it throws this error:
TypeError: Cannot read property 'length' of undefined
What am I doing wrong?
Here is my code snippet
var crypto1 = require("crypto-js");
var key = new ArrayBuffer(16)
key = [
43,
57,
97,
-68,
-63,
-61,
-40,
9,
50,
87,
-104,
101,
63,
34,
-78,
60,
];
const tripledes = require("crypto-js/tripledes")
const init = tripledes.encrypt
let ciphertext = init('12345586', key).toString();
console.log(base64.encode(ciphertext));
Solution 1:[1]
It seems that key
in tripledes.encrypt(text, key)
must be string
var crypto1 = require("crypto-js");
var key = new ArrayBuffer(16)
key = [
43,
57,
97,
-68,
-63,
-61,
-40,
9,
50,
87,
-104,
101,
63,
34,
-78,
60,
];
const tripledes = require("crypto-js/tripledes")
const init = tripledes.encrypt
// let ciphertext = init('12345586', key <--- ).toString();
let ciphertext = init('12345586', key.toString()).toString();
console.log(ciphertext);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |