This topic contains 2 replies, has 2 voices, and was last updated by henrē 4 years, 6 months ago.

  • Author
    Posts
  • #21260 Score: 1

    maike9
    • Contributions: 0
    • Level 1

    Trying to create a Security Access Token to connect to Azure Service Bus. Getting the following error when calling hmac.Digest method.

    error code: JS_EXCEPTION error message:{"type":"error.SuiteScriptError","name":"A N_ERROR_OCCURRED_WHILE_DECRYPT_PASSWORDGUID","mess age":"An error occurred while decrypting a credential.","stack":["createError(N/error)","(/SuiteScripts/AzureServiceBus/helloworld.js:48)"

    Code:
    var generateSasToken = function(resourceUri, signingKey, policyName, expiresInMins) {

    resourceUri = encodeURIComponent(resourceUri);

    // Set expiration in seconds
    var expires = (Date.now() / 1000) + expiresInMins * 60;
    expires = Math.ceil(expires);
    var toSign = resourceUri + 'n' + expires;

    // Use crypto
    var base64 = encode.convert({
    string: signingKey,
    inputEncoding: encode.Encoding.UTF_8,
    outputEncoding: encode.Encoding.BASE_64
    });

    var sKey = crypto.createSecretKey({
    guid: base64,
    encoding: encode.Encoding.BASE_64
    });

    var hmac = crypto.createHmac({
    algorithm: crypto.HashAlg.SHA256,
    key: sKey});

    hmac.update({
    input: toSign,
    inputEncoding: encode.Encoding.UTF_8});

    var digest = hmac.digest({
    outputEncoding: encode.Encoding.BASE_64
    });
    var base64UriEncoded = encodeURIComponent(digest);

    // Construct autorization string
    var token = "SharedAccessSignature sr=" + resourceUri + "&sig=" + base64UriEncoded + "&se=" + expires;
    if (policyName) token += "&skn="+policyName;
    return token;

    };
    This code was orginally derived from Node.JS code in the attached link.

    https://docs.microsoft.com/en-us/azu…oken-structure
    This is a cached copy. Click here to see the original post.

    This post has received 1 vote up.
  • #21261 Score: 0

    saenzmariano
    • Contributions: 0
    • Level 1

    Wrong forum. This should go in the SuiteScript forum

  • #26117 Score: 0

    henrē
    Member
    • Contributions: 1
    • Level 1
    @henre

    Any updates on how to fix this issue? I’m currently encountering this as well.

You must be logged in to reply to this topic.