Skip to content

Instantly share code, notes, and snippets.

@jperocho
Created June 5, 2014 10:25
Show Gist options
  • Save jperocho/bb06ed4f0e8bedffe0fd to your computer and use it in GitHub Desktop.
Save jperocho/bb06ed4f0e8bedffe0fd to your computer and use it in GitHub Desktop.
A simple password encryption for node.js
/*jshint node: true, strict: true*/
'use strict';
var crypto = require('crypto');
module.exports = {
algo :'bf-ecb',
encoding :'utf8',
input_encoding: 'base64',
hashIt: function ( pass, salt ) {
var hash = crypto.createHash('sha512');
hash.update(pass, this.encoding);
hash.update(salt, this.encoding);
var hashed = hash.digest(this.input_encoding);
var cipher = crypto.createCipheriv(this.algo, salt, '');
var ciphered = cipher.update(hashed, this.encoding, this.input_encoding);
ciphered += cipher.final(this.input_encoding);
return ciphered;
},
checkIt: function ( pass, salt, hashedPass ) {
return this.hashIt(pass,salt) === hashedPass;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment