// Hard coded until I can get it to work var uri = "{name=space}.servicebus.windows.net/{topic-or-hub-name}"; var saName = "{policy-name}"; var saKey = '{SAS-Key-Use-for-Hash}'; var encoded = encodeURIComponent(uri); var now = new Date(); // Commented out to compare the Powershell output var week = 60*60*24*7; var ttl = Math.round(now.getTime() / 1000) + week; var ttl = now.getTime() + 300; var signature = encoded + '\n' + ttl; // These were from the Microsoft NodeJs code, but cannot find comparible objects // I think I am missing some UTF-8 String to Array method before calling crypto Hmac // var signatureUTF8 = utf8.encode(signature); // var hash = crypto.createHmac('sha256', saKey).update(signature).digest('base64'); var _sha256 = crypto.getSHA256(); _sha256.update(signature); _sha256.update(saKey); var hash = _sha256.digest64(); // Output has vaule for debug using proxy headers context.targetRequest.headers['Authentication'] = 'SharedAccessSignature sr=' + encoded + '&sig=' + encodeURIComponent(hash) + '&se=' + ttl + '&skn=' + saName;