Cannot read property 'salt' of undefined Node js Crypto-js

Viewed 5487

My Code working with debug but when I try to run giving this error . Why It's happens.

var CryptoJS = require("crypto-js");
require('dotenv').config();

getText = process.env.USER;

var bytes  = CryptoJS.AES.decrypt(getText, 'secret key 123');
var originalText = bytes.toString(CryptoJS.enc.Utf8);
 
console.log(originalText); 

and when I try read from .env giving this error.

2 Answers

This happens when getText is null or undefined

I have same yours and found my solutions:

Possibly: Check again your data encrypt, is that encrypt in a right way ? same key, same library ? json.stringify and json.parse ? Your .env file set up right ? Cause you don't show that code so we can not give more details.

Related