Skip to content
Advertisement

Uncaught TypeError: can’t access property “words”, key is undefined

I am having problems with two functions to encrypt and decrypt text in JavaScript.

I am currently using CryptoJS

I need to understand how the encryptation works to use it in a bigger project

JavaScript
JavaScript

I would really appreciate it your help.

Advertisement

Answer

You made a few errors in your code:

encryptar() and desencriptar() are both defined to take 2 parameters

so I set default values for these two functions equal to the values of the text fields.

JavaScript

So when you don’t pass a value, these are the defaults.

  • I removed the conversion to and from the CryptoJS objects using the String function. CryptoJS objects have their own built in .toString method which allows you to specify encoding.

  • I also cleaned up some duplicate tags in the html file.

Full code:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement