Created
September 8, 2014 20:22
-
-
Save akasfei/589173f1498751ac67ff to your computer and use it in GitHub Desktop.
Hash w/ Node
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
#!/usr/local/bin/node | |
var crypto = require('crypto'); | |
var hashes = crypto.getHashes(); | |
var i = process.argv.indexOf('-m'); | |
var hash; | |
if (i >= 0 && hashes.indexOf(process.argv[i + 1]) >= 0) | |
hash = crypto.createHash(process.argv[i + 1]); | |
else | |
hash = crypto.createHash('md5'); | |
var encoding = 'base64'; | |
if (process.argv.indexOf('-bin') >= 0) | |
encoding = 'binary'; | |
if (process.argv.indexOf('-hex') >= 0) | |
encoding = 'hex'; | |
hash.update(process.argv[process.argv.length - 1], 'utf-8'); | |
console.log(hash.digest(encoding)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment