/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/crypto', 'N/log'], function (crypto, log) {
function onRequest(context) {
let textToHash = 'Sample Text';
let hash = crypto.hash({
algorithm: crypto.HashAlg.SHA256,
input: textToHash
});
log.debug('Hashed Value:', hash);
context.response.write('SHA-256 Hashed Value: ' + hash);
}
return {
onRequest: onRequest
};
});
How It Works
- The
crypto.hash()function takes an input string and applies the SHA-256 algorithm. - The result is a unique, irreversible hash value.
- This is useful for password storage or data integrity checks.
Other Supported Hash Algorithms
The N/crypto module supports multiple hashing algorithms:
crypto.HashAlg.SHA1crypto.HashAlg.SHA256crypto.HashAlg.SHA512crypto.HashAlg.MD5