Created
May 23, 2018 13:52
-
-
Save sagardere/86174d948d21fa4e5946bfd3b5d7010b to your computer and use it in GitHub Desktop.
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
//Diffrent way to generate password in Nodejs | |
// 1 | |
var CryptoJS = require("crypto-js"); | |
var text = 'sagar'; | |
var password = 'sagar'; | |
var encrypted = CryptoJS.AES.encrypt(text, password); | |
encrypted = encrypted.toString(); | |
console.log('@encrypted ' + encrypted); | |
var decrypted = CryptoJS.AES.decrypt(encrypted, password); | |
decrypted = decrypted.toString(CryptoJS.enc.Utf8) | |
console.log('@decrypted ' + decrypted); | |
//2 | |
var passwordHash = require('password-hash'); | |
var hashPassword = passwordHash.generate('sagar',{algorithm:"sha256"}); | |
console.log('@hashPassword ' + hashPassword); | |
//3 | |
var crypto = require('crypto'); | |
function encrypt(data) { | |
var cipher = crypto.createCipher('aes-256-ecb', 'sagar'); | |
return cipher.update(data, 'utf8', 'hex') + cipher.final('hex'); | |
} | |
function decrypt(data) { | |
var cipher = crypto.createDecipher('aes-256-ecb', 'sagar'); | |
return cipher.update(data, 'hex', 'utf8') + cipher.final('utf8'); | |
} | |
var encryptPassword = encrypt('saaagar'); | |
console.log('@encryptPassword ' + encryptPassword); | |
var decryptPassword = decrypt(encryptPassword); | |
console.log('@decryptPassword ' + decryptPassword); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment