Generate password hash for ASP.NET Identity authentication
This code, written for Node.js 6.x, generates a password hash to use with ASP.NET Identity version 2.
The resulting base64-encoded string consist of a single byte
0 signifying this is a version 2 hash. Then comes a 16 bytes long salt, followed by 32 bytes long SHA-1 hashed (1000 rounds) password.
const crypto = require('crypto') const pass = 'foobar' const version = Buffer.alloc(1) // 1 zero-filled byte const salt = crypto.randomBytes(16) const hash = crypto.pbkdf2Sync(pass, salt, 1000, 32, 'sha1') const b64 = Buffer.concat([ version, salt, hash ]).toString('base64') console.log(b64)