Search code examples
javascriptcryptojs

Uncaught TypeError: Cannot read property '0' of undefined CryptoJS


I am using CryptoJS and I keep getting Uncaught TypeError. Basically, when I try to send the message an encrypt it, that is when I end up getting the error.

The error I am getting is within the cryptoJS package. Line 256 starts at var encrypted = CryptoJS.AES.encrypt(myString, myPassword);

I am assuming the issue is within the piece of code I have listed below, or there it is when I have been importing the package.

enter image description here

    var myString = messageInput.value;
    var myPassword = 11111;
    var encrypted = CryptoJS.AES.encrypt(myString, myPassword);

Solution

  • Answer written from comments in OP.

    Password be a string not a number. Rather than entering "11111" to test try "testpassword".