Created
September 22, 2011 00:08
-
-
Save adrianbravo/1233693 to your computer and use it in GitHub Desktop.
Basic Node.js crypto cipher/decipher example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto') | |
, key = 'salt_from_the_user_document' | |
, plaintext = 'password' | |
, cipher = crypto.createCipher('aes-256-cbc', key) | |
, decipher = crypto.createDecipher('aes-256-cbc', key); | |
cipher.update(plaintext, 'utf8', 'base64'); | |
var encryptedPassword = cipher.final('base64') | |
decipher.update(encryptedPassword, 'base64', 'utf8'); | |
var decryptedPassword = decipher.final('utf8'); | |
console.log('encrypted :', encryptedPassword); | |
console.log('decrypted :', decryptedPassword); |
TypeError: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
Note: This error appears when the Decrypt function receives other string different to the encrypted string 😄 👊
Source: It just occurred to me
@dkhonig Agree.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.levigross.com/2014/03/30/how-to-write-an-encrypt-and-decrypt-api-for-data-at-rest-in-nodejs/