-
Notifications
You must be signed in to change notification settings - Fork 77
Description
Your Node.js aes encryption examples appeared very high in Google search results, and I found them very helpful – thanks!
However, playing around with it I noticed that the same ciphertext is generated each time, which is certainly not best practice...
Going through the Node crypto documentation, I noticed they say:
The implementation of crypto.createCipher() derives keys using the OpenSSL function EVP_BytesToKey with the digest algorithm set to MD5, one iteration, and no salt. The lack of salt allows dictionary attacks as the same password always creates the same key. The low iteration count and non-cryptographically secure hash algorithm allow passwords to be tested very rapidly.
In line with OpenSSL's recommendation to use pbkdf2 instead of EVP_BytesToKey it is recommended that developers derive a key and IV on their own using crypto.pbkdf2 and to use [crypto.createCipheriv()][] to create the Cipher object.
Deriving IVs seems rather involved. Do you have any examples of how to do this?