Anyone very familiar with the Crypto module? Seem ...
# suitescript
s
Anyone very familiar with the Crypto module? Seem like hashes etc are one thing that's way harder in 2.0 vs 1.0..... Trying to work with a 3rd party platform where they send a hmac header in their request I have hitting a suitelet, that is a SHA256 hash of a secret from their side which I will add as a script parameter, and what's being sent. Their suggested methodology for verification is here and the below gets me the string I need for hash comparison I believe.... but buggered if I can get any Crypto methods working... I feel like I shouldn't need to be setting up additional scripts to generate a GUID etc for such a simple requirement?
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 *@NModuleScope SameAccount
 */

define(["N/runtime"], function (runtime) {
    function onRequest(params) {
        var ssoSecret = runtime.getCurrentScript().getParameter("custscript_sso_secret");
        var paramsArray = [];
        for (var i in params.request.parameters) {
            if (i != "hmac") paramsArray.push([encodeURIComponent(i) + "=" + encodeURIComponent(params.request.parameters[i])]);
        }
        paramsArray.sort();
        var hmacMessage = "";
        var count = 0;
        for (var i in paramsArray) {
            if (count > 0) {
                hmacMessage += "&";
            }
            hmacMessage += paramsArray[i];
            count++;
        }
        log.debug({
            title: "ssoSecret",
            details: ssoSecret
        });
        log.debug({
            title: "hmacMessage ",
            details: hmacMessage
        });
}

    return {
        onRequest: onRequest
    };
});