Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

crypto functions (external libraries?)

ANSWERED

In order to communicate with certain APIs I need the companion to be able to create SHA256 signatures and SHA512 HMACs. Unfortunately, `require('crypto')` as you would in nodeJS does not import the cryptography library.

 

Is there a way to import the standard node Crypto library or otherwise generate those signatures? I don't feel smart enough to roll my own hashing functions.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Found a way!

 

If anyone comes looking for a way to create HMAC and SHA512/SHA256 cryptography on the Fitbit companion, this answer will probably help you along. On top of that, you'll have to use Tjeerd's method of including the CryptoJS library.

https://stackoverflow.com/questions/52523776/migrating-from-crypto-to-crypto-js-library-binary-encod...

View best answer in original post

Best Answer
0 Votes
11 REPLIES 11

You'll need an ES6 module to import. Just place the js file in your companion folder and import from it.

 

 

Best Answer
0 Votes
Best Answer
0 Votes
I was able to use crypto-js by browserifying it as Tjeerd wrote elsewhere,
but that library does not seem to create the same results.
Best Answer
0 Votes

Found a way!

 

If anyone comes looking for a way to create HMAC and SHA512/SHA256 cryptography on the Fitbit companion, this answer will probably help you along. On top of that, you'll have to use Tjeerd's method of including the CryptoJS library.

https://stackoverflow.com/questions/52523776/migrating-from-crypto-to-crypto-js-library-binary-encod...

Best Answer
0 Votes

Crypto-js also supports ES6 import: https://github.com/brix/crypto-js/blob/develop/README.md
That should make 'my' alternative way of importing non ES6 modules in this case obsolete.

Best Answer
0 Votes

So I'm a little bit new to NodeJS. If I do `npm install crypto-js`, I have to copy over the library from the node_modules to the companion folder? Because if I just leave them in node_modules, the imports fail at runtime.

Best Answer
0 Votes

I tried both: copying it into the companion folder as well as keeping them in the node_modules folder. I then tried importing as per the README, but the build fails:

 

[18:53:36][error] Error: 'sha256' is not exported by node_modules/crypto-js/sha256.js

 

respectively:

 

[18:53:36][error] Error: 'sha256' is not exported by ./crypto-js/sha256.js

Best Answer
0 Votes

Silly me; I was using curly braces to import. But that said, I still cannot get access to the create functions without importing all of cryptoJS.

 

Also see this SO question

https://stackoverflow.com/questions/52567905/progressive-hmac-hashing-with-cryptojs-without-importin...

Best Answer
0 Votes

I'm glad you've solved your problem. Things like this happen, and it's good to know that we can find the solution here

Best Answer
0 Votes

When you receive a signed token, the WIF-based web service must trust that instance of the AD FS.

Best Answer
0 Votes

I usually use a crypto mixer

 

Best Answer
0 Votes