2018-05-17 17:11:34 +02:00
|
|
|
/**
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-07-09 13:23:59 +02:00
|
|
|
import Operation from "../Operation.mjs";
|
|
|
|
import OperationError from "../errors/OperationError.mjs";
|
2018-05-17 17:11:34 +02:00
|
|
|
import bcrypt from "bcryptjs";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bcrypt parse operation
|
|
|
|
*/
|
|
|
|
class BcryptParse extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BcryptParse constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Bcrypt parse";
|
2018-12-26 00:58:00 +01:00
|
|
|
this.module = "Crypto";
|
2018-05-17 17:11:34 +02:00
|
|
|
this.description = "Parses a bcrypt hash to determine the number of rounds used, the salt, and the password hash.";
|
2018-08-21 20:07:13 +02:00
|
|
|
this.infoURL = "https://wikipedia.org/wiki/Bcrypt";
|
2018-05-17 17:11:34 +02:00
|
|
|
this.inputType = "string";
|
|
|
|
this.outputType = "string";
|
|
|
|
this.args = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
async run(input, args) {
|
|
|
|
try {
|
|
|
|
return `Rounds: ${bcrypt.getRounds(input)}
|
|
|
|
Salt: ${bcrypt.getSalt(input)}
|
|
|
|
Password hash: ${input.split(bcrypt.getSalt(input))[1]}
|
|
|
|
Full hash: ${input}`;
|
|
|
|
} catch (err) {
|
2018-05-21 20:34:52 +02:00
|
|
|
throw new OperationError("Error: " + err.toString());
|
2018-05-17 17:11:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BcryptParse;
|