CryptoJS key generator

1.5k views Asked by At

I have a reference to CryptoJS v3.1.2 and when trying the following javascript code:

var txtpassword = document.getElementById("myPassword").value.trim();
var salt = CryptoJS.lib.WordArray.random(128 / 8);
var key256Bits = CryptoJS.PBKDF2(txtpassword, salt, { keySize: 256 / 32 });

It blows up on PBKDF2, proclaiming "Object doesn't support property or method 'PBKDF2'". I see many references online to calling PBKDF2 like this, what am I missing?

2

There are 2 answers

0
Sean On

I was missing all the rest of the associated js files. I was able to download the complete library from here

https://code.google.com/archive/p/crypto-js/downloads

0
RBILLC On

Including this CDN fixed the reference error on my end: <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/pbkdf2.js"></script>