hmac-isomorphic
v0.0.1
Published
isomorphic mechanism to generate hmac digest, using Crypto on node.js and crypto.subtle in the browser
Downloads
4
Readme
hmac-isomorphic
Usage
Make sure that whatever build system you are using (Webpack etc) is honoring the browser field in package.json. Then import the library.
The module provides a single function that returns a promise, both in node and in the browser. There are three arguments:
- algo, string: the signing algorithim to use. Can be sha256, sha512, etc. Be sure to use the naming mechanism from nodejs, e.g.
sha256
notSHA-256
. - key, string: the encryption key to use. This should be secret.
- message, string: the message to generate the signature from.
const createHmacDigest = require('hmac-isomorphic');
createHmacDigest('sha256', 'abc123', 'def456').then(console.log);
Implementation
- Uses native crypto in NodeJS and the native subtle crypto in the browser.