Created
June 5, 2014 10:25
-
-
Save jperocho/bb06ed4f0e8bedffe0fd to your computer and use it in GitHub Desktop.
A simple password encryption for node.js
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
/*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