Skip to content
Advertisement

Translating JS crypto.createHmac to Xojo Crypto.HMAC

I am trying to translate this block in Javascript:

const crypto = require('crypto'),
    shared_key = 'kw4qSnpSwXzgiv5yxYpZZmFEd9QAeiKTQ6OuyMja',
    signing_string = 'licenseSpringndate: Tue, 07 Jun 2011 20:51:35 GMT';

let signature = crypto.createHmac('sha256', shared_key).update(signing_string).digest('base64');

console.log(signature);
// UDysfR6MndUZReo07Y9r+vErn8vSxrnQ5ulit18iJ/Q=

Into Xojo:

Var shared_key as String = "kw4qSnpSwXzgiv5yxYpZZmFEd9QAeiKTQ6OuyMja"
Var signing_string as String =  "licenseSpringndate: Tue, 07 Jun 2011 20:51:35 GMT"

Var hash As String
hash = EncodeBase64(Crypto.HMAC(shared_key, signing_string, Crypto.HashAlgorithms.SHA256))
MessageBox(hash)
//Q4BAhsu1Xw3LsBZ+BCLShWQDbmJ2j/eFXzvF9T6n9tU=

I am getting two different hashed strings, but expect they should be the same. Are these algorithms equivalent?

Advertisement

Answer

It turned out to be this:

Var signing_string as String =  "licenseSpring" + EndOfLine.UNIX + "date: Tue, 07 Jun 2011 20:51:35 GMT"
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement