Skip to content

Instantly share code, notes, and snippets.

@azakordonets
Last active July 25, 2022 10:21
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save azakordonets/e436ccbdb2a4aedac52a to your computer and use it in GitHub Desktop.
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
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();
}
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