New operation: Generate SSHA Hash

This commit is contained in:
Daniel Wallace 2024-11-05 17:48:00 +11:00 committed by WORKGROUP\dwallace
parent 3822c6c520
commit 843e65242e
2 changed files with 48 additions and 1 deletions

View file

@ -432,7 +432,8 @@
"CRC-8 Checksum",
"CRC-16 Checksum",
"CRC-32 Checksum",
"TCP/IP Checksum"
"TCP/IP Checksum",
"Generate SSHA Hash"
]
},
{

View file

@ -0,0 +1,46 @@
/**
* @author git-commit-amen [daniel@danielwallace.com.au]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import CryptoJS from "crypto-js";
/**
* Generate SSHA Hash operation
*/
class GenerateSSHAHash extends Operation {
/**
* GenerateSSHAHash constructor
*/
constructor() {
super();
this.name = "Generate SSHA Hash";
this.module = "Crypto";
this.description = "Generates an RFC 2307-compliant, cryptographically-secure SSHA (Salted SHA1) password hash - commonly used for storing passwords in systems such as OpenLDAP.";
this.infoURL = "https://www.openldap.org/faq/data/cache/347.html";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
if (!input) return "";
const salt = CryptoJS.lib.WordArray.random(128/8).toString().substr(0, 4);
const hash = CryptoJS.SHA1(input + salt);
const result = CryptoJS.enc.Latin1.parse(hash.toString(CryptoJS.enc.Latin1) + salt).toString(CryptoJS.enc.Base64);
return `{SSHA}${result}`;
}
}
export default GenerateSSHAHash;