-
-
Save chrisyip/972cc8639bfff9d5883670e5de576953 to your computer and use it in GitHub Desktop.
Basic Node.js crypto cipher/decipher example.
This file contains hidden or 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
'use strict' | |
const crypto = require('crypto') | |
const key = 'salt_from_the_user_document' | |
const plaintext = '56d008a27c36552a0f97b291' | |
const cipher = crypto.createCipher('aes-256-cbc', key) | |
const decipher = crypto.createDecipher('aes-256-cbc', key) | |
let encryptedPassword = cipher.update(plaintext, 'utf8', 'base64') | |
encryptedPassword += cipher.final('base64') | |
let decryptedPassword = decipher.update(encryptedPassword, 'base64', 'utf8') | |
decryptedPassword += decipher.final('utf8') | |
console.log('encrypted :', encryptedPassword) | |
console.log('decrypted :', decryptedPassword) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment