# Translating JS crypto.createHmac to Crypto.HMAC

**URL:** <https://forum.xojo.com/t/translating-js-crypto-createhmac-to-crypto-hmac/59728>\
**Category:** General\
**Created:** [December 11, 2020, 10:48pm UTC](https://forum.xojo.com/t/translating-js-crypto-createhmac-to-crypto-hmac/59728 "2020-12-11T22:48:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Gerson](https://forum.xojo.com/user_avatar/forum.xojo.com/adam_gerson/32/2765_2.png) [@Adam\_Gerson](https://forum.xojo.com/u/Adam_Gerson)\
**Post date:** [December 11, 2020, 10:48pm UTC](https://forum.xojo.com/t/translating-js-crypto-createhmac-to-crypto-hmac/59728/1 "2020-12-11T22:48:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [December 11, 2020, 11:00pm UTC](https://forum.xojo.com/t/translating-js-crypto-createhmac-to-crypto-hmac/59728/2 "2020-12-11T23:00:25Z")

</div>

Edit: Disregard, see next post.

Maybe it should be:

```auto
Var shared_key as String = DecodeBase64("kw4qSnpSwXzgiv5yxYpZZmFEd9QAeiKTQ6OuyMja")

```

?

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [December 11, 2020, 11:08pm UTC](https://forum.xojo.com/t/translating-js-crypto-createhmac-to-crypto-hmac/59728/3 "2020-12-11T23:08:26Z")

</div>

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"
```

---

<div class="post-metadata">

**Author:** ![Adam\_Gerson](https://forum.xojo.com/user_avatar/forum.xojo.com/adam_gerson/32/2765_2.png) [@Adam\_Gerson](https://forum.xojo.com/u/Adam_Gerson)\
**Post date:** [December 12, 2020, 12:32am UTC](https://forum.xojo.com/t/translating-js-crypto-createhmac-to-crypto-hmac/59728/4 "2020-12-12T00:32:48Z")

</div>

> [@Andrew\_Lambert](#):
>
> `Var signing_string as String = "licenseSpring" + EndOfLine.UNIX + "date: Tue, 07 Jun 2011 20:51:35 GMT"`

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

---

<div class="post-metadata">

**Author:** ![John\_Kelly](https://forum.xojo.com/user_avatar/forum.xojo.com/john_kelly/32/12223_2.png) [@John\_Kelly](https://forum.xojo.com/u/John_Kelly)\
**Post date:** [December 24, 2022, 6:15pm UTC](https://forum.xojo.com/t/translating-js-crypto-createhmac-to-crypto-hmac/59728/5 "2022-12-24T18:15:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [December 24, 2022, 7:11pm UTC](https://forum.xojo.com/t/translating-js-crypto-createhmac-to-crypto-hmac/59728/6 "2022-12-24T19:11:14Z")

</div>

For DRM / licensing of Xojo Desktop applications, I’ve built an end-to-end Xojo code system 🙂  
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](https://strawberrysw.com/tplm)  
I’m also happy to answer any questions! [support@strawberrysw.com](mailto:support@strawberrysw.com)
