mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-17 09:28:31 +01:00
29 lines
603 B
JavaScript
29 lines
603 B
JavaScript
|
/**
|
||
|
* Hashing resources.
|
||
|
*
|
||
|
* @author n1474335 [n1474335@gmail.com]
|
||
|
*
|
||
|
* @copyright Crown Copyright 2016
|
||
|
* @license Apache-2.0
|
||
|
*/
|
||
|
|
||
|
import Utils from "../Utils";
|
||
|
import CryptoApi from "crypto-api/src/crypto-api";
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Generic hash function.
|
||
|
*
|
||
|
* @param {string} name
|
||
|
* @param {ArrayBuffer} input
|
||
|
* @param {Object} [options={}]
|
||
|
* @returns {string}
|
||
|
*/
|
||
|
export function runHash(name, input, options={}) {
|
||
|
const msg = Utils.arrayBufferToStr(input, false),
|
||
|
hasher = CryptoApi.getHasher(name, options);
|
||
|
hasher.update(msg);
|
||
|
return CryptoApi.encoder.toHex(hasher.finalize());
|
||
|
}
|
||
|
|