RE: String Encryption with SHA256

I need to create a Digest(Hash) of a JSON string and a Header to send information to my Cybersource Account. The Hash needs to be SHA256. In Suitescript 1.0 , nalapiEncrypt is available, but it only hashed with SHA-1 which is now deprecated. In Suitescript 2.x the N/Crypto Modules crypto.Hash.digest function appears to be the answer, but I would be calling the function from a Suitescript 1.0 suitelet. I see references to people successfully calling 2.0 functions from 1.0, but I am confused as to the method. Does anyone have a clear explanation or advise?

larryw11980 Rookie Asked on May 26, 2020 in SuiteBuilder.
Add Comment
1 Answers
Best answer

SuiteScript 1.0 will work with the crypto-js library, and it may be easier to work with than the NetSuite crypto libraries.  It isn’t possibly to directly call SS 2.0 code from 1.0.  You can add the crypto-js.min.js as a library to your 1.0 script, then you can just use a function similar to the following to generate the Digest:

function generateDigest(jsonString) {
    return 'SHA-256=' + CryptoJS.enc.Base64.stringify(CryptoJS.SHA256(jsonString));
}
var digest = generateDigest(jsonString);
nlapiLogExecution('DEBUG', 'Digest', digest);

You’ll need to tweak this according to the CyberSource documentation and the integration method that you are using.

Beginner Answered on May 26, 2020.

Thanks, that works!

on June 5, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.