2019-02-22 09:59:42 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
var program = require('commander');
|
|
|
|
var RandomString = require("randomstring");
|
|
|
|
var Util = require("util");
|
|
|
|
var crypt = require("crypt3");
|
|
|
|
|
|
|
|
function ssha512(password, saltSize, rounds) {
|
|
|
|
// $6 means SHA512
|
|
|
|
const _salt = Util.format("$6$rounds=%d$%s", rounds,
|
|
|
|
RandomString.generate(saltSize));
|
|
|
|
|
|
|
|
const hash = crypt(password, _salt);
|
|
|
|
return Util.format("{CRYPT}%s", hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
let password;
|
|
|
|
|
|
|
|
program
|
|
|
|
.option('-s, --salt <size>', 'The size of the salt to generate.')
|
|
|
|
.option('-r, --rounds <rounds>', 'The number of rounds.')
|
|
|
|
.arguments('<password>')
|
|
|
|
.action(function (_password) {
|
|
|
|
password = _password;
|
|
|
|
})
|
|
|
|
.parse(process.argv);
|
|
|
|
|
2019-03-03 22:55:34 +00:00
|
|
|
if (!password) {
|
|
|
|
program.help();
|
|
|
|
}
|
|
|
|
|
2019-02-22 09:59:42 +00:00
|
|
|
console.log(ssha512(password, program.salt || 16, program.rounds || 500000));
|