This topic contains 3 replies, has 0 voices, and was last updated by mayerlench 6 years, 6 months ago.

  • Author
    Posts
  • #18247

    charles.wallace.arcserve

    I am trying to implement a JSON Web Token, and thus trying to get crypto.hmac to work, but I’m having issues with it. I made a password tool from a modified version of the suitelet from this thread, and I have a password guid that I have generated and restricted for use on my custom script id, that I am using in that custom script. However, each time the code gets to the .digest() call, it throws UNEXPECTED_ERROR. I’m still new to SuiteScript and I’m not sure what I am doing wrong:

    Code:
    var sKey = crypto.createSecretKey({
    guid: “6332f5d7575a481388a24b924292d552”, // restrictToDomains=[‘system.sandbox.netsuite.com’], restrictToScriptIds=[]
    encoding: encode.Encoding.HEX
    });
    var hmacSignature = crypto.createHmac({
    algorithm: crypto.HashAlg.SHA256,
    key: sKey,
    });

    hmacSignature.update({
    input: encHeader + “.” + encPayload,
    inputEncoding: encode.Encoding.UTF_8
    });
    var signature = hmacSignature.digest({
    outputEncoding: encode.Encoding.BASE_64_URL_SAFE
    });
    return encHeader + “.” + encPayload + “.” + signature;
    Any assistance would be greatly appreciated.

    Thanks,

    Charles
    This is a cached copy. Click here to see the original post.

  • #18248

    holly2k

    +1, unable to run the example code at all, hope NS provide working example other than this a UNEXCEPTED_ERROR case

  • #18249

    BrettKnights

    Did you get this? You have to use form.addSecretKeyField not addCredentialField

    The NS example shows

    Code:
    form.addCredentialField({
    id : ‘username’,
    label : ‘Pwd’,
    restrictToDomains : [config.host],
    restrictToScriptIds : config.targetScript,
    restrictToCurrentUser : false
    });
    but for HMAC it should be:

    Code:
    form.addSecretKeyField({
    id : ‘username’,
    label : ‘Pwd’,
    restrictToScriptIds : config.targetScript,
    restrictToCurrentUser : false
    });
    If you are having problems with interoperability the other thing to watch for is case. Node.js at least produces its hex values lower case but the SS2 Hmac digest gives upper case. So convert before comparing.

  • #18250

    mayerlench

    Having the same issue right now. Netsuites example code does not work!

You must be logged in to reply to this topic.