This topic contains 2 replies, has 2 voices, and was last updated by henrē 5 years, 2 months ago.
-
AuthorPosts
-
May 11, 2018 at 2:53 pm #21260
maike9Trying 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. -
May 11, 2018 at 3:54 pm #21261
saenzmarianoWrong forum. This should go in the SuiteScript forum
-
September 11, 2019 at 6:28 pm #26117
Any updates on how to fix this issue? I’m currently encountering this as well.
-
AuthorPosts
You must be logged in to reply to this topic.