Variable: hash ​
hash: object;
Hashing functions for generating and comparing hashes.
Type declaration ​
Generate Hash ​
generate() ​
generate(text, algorithm): Promise<string>;
Generates a hash for the given text using the specified hash algorithm.
Parameters ​
text ​
string
The input text to hash.
algorithm ​
HashAlgorithm
= HashAlgorithm.SHA512
The hash algorithm to use. Defaults to SHA512.
Returns ​
Promise
<string
>
A Promise that resolves to the generated hash as a hexadecimal string.
Throws ​
Will throw an error if the input text is empty or whitespace or if the algorithm is not supported.
Example ​
const hashedValue = await cryptor.hash.generate('myPassword');
console.log(hashedValue); // Outputs the hashed value of 'myPassword'
Verify Hash ​
verify() ​
verify(
text,
hash,
algorithm): Promise<boolean>;
Compares a given text with a hash to determine if they match.
Parameters ​
text ​
string
The input text to compare.
hash ​
string
The hash to compare against.
algorithm ​
HashAlgorithm
= HashAlgorithm.SHA512
The hash algorithm used for generating the hash. Defaults to SHA512.
Returns ​
Promise
<boolean
>
A Promise that resolves to true
if the text matches the hash, false
otherwise.
Throws ​
Will throw an error if the input text or hash is empty or whitespace.
Example ​
const isMatch = await cryptor.hash.verify('myPassword', hashedValue);
console.log(isMatch); // Outputs true if the text matches the hash, otherwise false