Create a Secure Key Using SHA512

The following sample demonstrates the APIs needed to generate a secure key using the SHA512 hashing algorithm. The GUID in this sample is a placeholder. You must replace it with a valid value from your NetSuite account. To create a real password GUID, obtain a password value from a credential field on a form. For more information, see Form.addCredentialField(options). Also see the Create a Suitelet to Request User Credentials, Create a Secret Key, and Encode a Sample String that shows how to create a form field that generates a GUID.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

          /**
 * @NApiVersion 2.1
 */
/**This sample demonstrates the APIs needed to generate a secure key using the SHA512 hashing algorithm.
*  The mySecret variable is a placeholder that must be replaced with a valid secret from your NetSuite account. 
*  For information about  secrets management page, see Account Administration > Authentication > Secrets Management
 * in the Help Center.
**/

require(['N/crypto', 'N/encode', 'N/runtime'], (crypto, encode, runtime) => {
    function createSecureKeyWithHash() {
        let mySecret = 'custsecret_my_secret';    //secret id take from secrets management page

        let sKey = crypto.createSecretKey({
            secret: mySecret,
            encoding: encode.Encoding.UTF_8
        });

        let hmacSHA512 = crypto.createHmac({
            algorithm: crypto.HashAlg.SHA512,
            key: sKey
        });

        hmacSHA512.update({
            input: inputString,
            inputEncoding: encode.Encoding.BASE_64
        });

        let digestSHA512 = hmacSHA512.digest({
            outputEncoding: encode.Encoding.HEX
        });
    }
    createSecureKeyWithHash();
}); 

        

General Notices