Last active
August 13, 2024 07:53
-
-
Save azakordonets/e436ccbdb2a4aedac52a to your computer and use it in GitHub Desktop.
This gist describes how to encode password with salt using SHA256 algorithm. It shows how to do it with google crypto-js library and Node.js module crypto
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'); | |
var passowrd = "123"; | |
var salt = "test@gmail.com"; | |
passowrd = crypto.createHash('sha256') | |
.update(passowrd, "utf8") | |
.update(makeHash(salt)) | |
.digest("base64"); | |
console.log(passowrd); | |
function makeHash(val) { | |
return crypto.createHash('sha256').update(val, "utf8").digest(); | |
} |
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 CryptoJS = require('crypto-js'); | |
var algo = CryptoJS.algo.SHA256.create(); | |
algo.update(password, 'utf-8'); | |
algo.update(CryptoJS.SHA256(salt), 'utf-8'); | |
var hash = algo.finalize().toString(CryptoJS.enc.Base64); | |
console.log(hash); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment