1

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));
Muhammad Talha Akbar
  • 9,952
  • 6
  • 38
  • 62
hanan
  • 532
  • 2
  • 7
  • 23
  • if you fixed your problem, plz share your solution. if my answer helped you, I would appreciate if you accept my answer – R Pasha Jul 13 '20 at 17:23

1 Answers1

2

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);
R Pasha
  • 700
  • 5
  • 21