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');

// 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))

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.


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!

@Adam_Gerson, were you able to successfully integrate to LicenseSpring? I am looking into that as a possible solution for licensing desktop apps.

For DRM / licensing of Xojo Desktop applications, I’ve built an end-to-end Xojo code system :slight_smile:
No plugins, no black boxes!

TPLM features a drop-in Desktop module for protecting your software and a Xojo Web app that acts as an online licensing server. The Web panel provides hooks to integrate with FastSpring ready to go. The Desktop module offers many standard DRM features such as hardware-locked licensing, verified online activation, and offline licensing.

More information can be found here: TPLM: Xojo DRM - Strawberry Software
I’m also happy to answer any questions!