Gathering detailed insights and metrics for jwa
Gathering detailed insights and metrics for jwa
Gathering detailed insights and metrics for jwa
Gathering detailed insights and metrics for jwa
npm install jwa
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
99 Stars
92 Commits
40 Forks
10 Watching
2 Branches
14 Contributors
Updated on 03 Oct 2024
JavaScript (94.76%)
Makefile (5.24%)
Cumulative downloads
Total Downloads
Last day
-6.7%
4,627,765
Compared to previous day
Last week
1.5%
26,935,967
Compared to previous week
Last month
5.5%
114,083,605
Compared to previous month
Last year
26.4%
1,157,744,888
Compared to previous year
4
A JSON Web Algorithms implementation focusing (exclusively, at this point) on the algorithms necessary for JSON Web Signatures.
This library supports all of the required, recommended and optional cryptographic algorithms for JWS:
alg Parameter Value | Digital Signature or MAC Algorithm |
---|---|
HS256 | HMAC using SHA-256 hash algorithm |
HS384 | HMAC using SHA-384 hash algorithm |
HS512 | HMAC using SHA-512 hash algorithm |
RS256 | RSASSA using SHA-256 hash algorithm |
RS384 | RSASSA using SHA-384 hash algorithm |
RS512 | RSASSA using SHA-512 hash algorithm |
PS256 | RSASSA-PSS using SHA-256 hash algorithm |
PS384 | RSASSA-PSS using SHA-384 hash algorithm |
PS512 | RSASSA-PSS using SHA-512 hash algorithm |
ES256 | ECDSA using P-256 curve and SHA-256 hash algorithm |
ES384 | ECDSA using P-384 curve and SHA-384 hash algorithm |
ES512 | ECDSA using P-521 curve and SHA-512 hash algorithm |
none | No digital signature or MAC value included |
Please note that PS* only works on Node 6.12+ (excluding 7.x).
In order to run the tests, a recent version of OpenSSL is required. The version that comes with OS X (OpenSSL 0.9.8r 8 Feb 2011) is not recent enough, as it does not fully support ECDSA keys. You'll need to use a version > 1.0.0; I tested with OpenSSL 1.0.1c 10 May 2012.
To run the tests, do
1$ npm test
This will generate a bunch of keypairs to use in testing. If you want to
generate new keypairs, do make clean
before running npm test
again.
I spawn openssl dgst -sign
to test OpenSSL sign → JS verify and
openssl dgst -verify
to test JS sign → OpenSSL verify for each of the
RSA and ECDSA algorithms.
Creates a new jwa
object with sign
and verify
methods for the
algorithm. Valid values for algorithm can be found in the table above
('HS256'
, 'HS384'
, etc) and are case-sensitive. Passing an invalid
algorithm value will throw a TypeError
.
Sign some input with either a secret for HMAC algorithms, or a private key for RSA and ECDSA algorithms.
If input is not already a string or buffer, JSON.stringify
will be
called on it to attempt to coerce it.
For the HMAC algorithm, secretOrPrivateKey
should be a string or a
buffer. For ECDSA and RSA, the value should be a string representing a
PEM encoded private key.
Output base64url formatted. This is for convenience as JWS expects the signature in this format. If your application needs the output in a different format, please open an issue. In the meantime, you can use brianloveswords/base64url to decode the signature.
As of nodejs v0.11.8, SPKAC support was introduce. If your nodeJs
version satisfies, then you can pass an object { key: '..', passphrase: '...' }
Verify a signature. Returns true
or false
.
signature
should be a base64url encoded string.
For the HMAC algorithm, secretOrPublicKey
should be a string or a
buffer. For ECDSA and RSA, the value should be a string represented a
PEM encoded public key.
HMAC
1const jwa = require('jwa'); 2 3const hmac = jwa('HS256'); 4const input = 'super important stuff'; 5const secret = 'shhhhhh'; 6 7const signature = hmac.sign(input, secret); 8hmac.verify(input, signature, secret) // === true 9hmac.verify(input, signature, 'trickery!') // === false
With keys
1const fs = require('fs'); 2const jwa = require('jwa'); 3const privateKey = fs.readFileSync(__dirname + '/ecdsa-p521-private.pem'); 4const publicKey = fs.readFileSync(__dirname + '/ecdsa-p521-public.pem'); 5 6const ecdsa = jwa('ES512'); 7const input = 'very important stuff'; 8 9const signature = ecdsa.sign(input, privateKey); 10ecdsa.verify(input, signature, publicKey) // === true
MIT
Copyright (c) 2013 Brian J. Brennan
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
Found 2/20 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More