Translating JS crypto.createHmac to Crypto.HMAC

I am trying to translate this block in Javascript:

const crypto = require('crypto'),
    shared_key = 'kw4qSnpSwXzgiv5yxYpZZmFEd9QAeiKTQ6OuyMja',
    signing_string = 'licenseSpring\ndate: 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 =  "licenseSpring\ndate: 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?

Edit: Disregard, see next post.

Maybe it should be:

Var shared_key as String = DecodeBase64("kw4qSnpSwXzgiv5yxYpZZmFEd9QAeiKTQ6OuyMja")

?

Got it.

This:

Var signing_string as String =  "licenseSpring\ndate: Tue, 07 Jun 2011 20:51:35 GMT"

Should be this:

Var signing_string as String =  "licenseSpring" + EndOfLine.UNIX + "date: Tue, 07 Jun 2011 20:51:35 GMT"
1 Like

Thank you! Not sure I would have ever found my way to that!