Skip to content

Instantly share code, notes, and snippets.

@paulomcnally
Last active September 23, 2019 22:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulomcnally/c9e674cfc5b0a950233d to your computer and use it in GitHub Desktop.
Save paulomcnally/c9e674cfc5b0a950233d to your computer and use it in GitHub Desktop.
Generating PBKDF2 keys in C# and NodeJS
public string hash(string pwd,string salt) {
Rfc2898DeriveBytes pdb;
Byte[] byteValue = System.Text.Encoding.UTF8.GetBytes(salt);
pdb = new Rfc2898DeriveBytes(pwd, byteValue, 1333);
return Convert.ToBase64String(pdb.GetBytes(32));
}
var crypto = require('crypto');
var hash = function(password, salt) {
var pass = crypto.pbkdf2Sync(password, salt, 1333, 32);
return new Buffer(pass).toString('base64')
}
@etiennejcharles
Copy link

etiennejcharles commented Sep 23, 2019

var pass = crypto.pbkdf2Sync(password, salt, 1333, 32);

should be

var pass = crypto.pbkdf2Sync(password, salt, 1333, 32, "sha1");
node v12.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment