Created
July 8, 2020 14:00
-
-
Save elementechemlyn/88e710bb79977e16b9f81ffe04366718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function meshAuthorisationToken (mailboxId, mailboxPassword, secretKey) { | |
// GS 2016-12-13 | |
// construct MESH authorisation token | |
var d = new Date(); | |
var ts = '' + d.getFullYear() | |
+ (d.getMonth() < 9 ? '0' + (d.getMonth()+1) : (d.getMonth()+1)) | |
+ (d.getDate() < 9 ? '0' + (d.getDate()) : (d.getDate())) | |
+ (d.getHours() < 10 ? '0' + d.getHours() : d.getHours()) | |
+ (d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()); | |
var nonce = generateUuid(); | |
var nonceCount = 1; | |
var msg = java.lang.String(mailboxId + ':' + nonce + ':' + nonceCount + ':' + mailboxPassword + ':' + ts); | |
var secretStr = java.lang.String(secretKey); | |
var mac = javax.crypto.Mac.getInstance("HmacSHA256"); | |
var secret = new javax.crypto.spec.SecretKeySpec(secretStr.getBytes("UTF-8"), "HmacSHA256"); | |
mac.init(secret); | |
var hash = javax.xml.bind.DatatypeConverter.printHexBinary(mac.doFinal(msg.getBytes("UTF-8"))).toLowerCase(); | |
var auth = 'NHSMESH ' + mailboxId + ':' + nonce + ':' + nonceCount + ':' + ts + ':' + hash; | |
return auth; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment