JSON Web Algorithms (JWA)
JSON Web Algorithms (JWA) for JSON Object Signing and Encryption (JOSE)
npm
Install via$ npm install --save json-web-algorithms
Signature Algorithms
HMAC (Hash-based Message Authentication Code)
Type | Signature / MAC & Hash algorithm |
---|---|
HS256 | HMAC using SHA-256 hash algorithm |
HS384 | HMAC using SHA-384 hash algorithm |
HS512 | HMAC using SHA-512 hash algorithm |
RSASSA (RSA Signature Scheme with Appendix)
Type | Signature / MAC & Hash algorithm |
---|---|
RS256 | RSASSA using SHA-256 hash algorithm |
RS384 | RSASSA using SHA-384 hash algorithm |
RS512 | RSASSA using SHA-512 hash algorithm |
ECDSA (Elliptic Curve Digital Signature Algorithm)
Type | Signature / MAC & 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 |
PLAIN
Type | Signature / MAC & Hash algorithm |
---|---|
PLAIN | No digital signature or MAC value included |
Usage
var JOSE = require( 'jose' )
// Sign something
var signature = JOSE.sign( 'HS256' input, key )
// Verify a signature
var isValid = JOSE.verify( 'HS256', signature, input, key )
API Reference
Object
JWA : JSON Web Algorithms
Kind: global variable
-
JWA :
Object
-
.SignatureAlgorithm :
function
-
.sign(algorithm, input, key) ⇒
Buffer
-
.verify(algorithm, signature, input, key) ⇒
Boolean
-
.SignatureAlgorithm :
function
JWA.SignatureAlgorithm : Kind: static class of JWA
new JWA.SignatureAlgorithm()
JWA SignatureAlgorithm
Buffer
JWA.sign(algorithm, input, key) ⇒ Sign an input with a given algorithm
Kind: static method of JWA
Returns: Buffer
- signature
Param | Type |
---|---|
algorithm | String |
input | Buffer |
key | Buffer |
Boolean
JWA.verify(algorithm, signature, input, key) ⇒ Verify a signature with a given algorithm
Kind: static method of JWA
Param | Type |
---|---|
algorithm | String |
signature | Buffer |
input | Buffer |
key | Buffer |
SignatureAlgorithm
Kind: global class
-
SignatureAlgorithm
- new SignatureAlgorithm(type, bits)
-
instance
-
._signECDSA(digest) ⇒
Buffer
-
.sign(input, key) ⇒
Buffer
-
._verifyHMAC(signature, input, key) ⇒
Boolean
-
._verifyRSA(signature, input, key) ⇒
Boolean
-
._verifyECDSA(signature, input, key) ⇒
Boolean
-
.verify(signature, input, key) ⇒
Boolean
-
._signECDSA(digest) ⇒
-
static
-
.type :
Object
-
.type :
new SignatureAlgorithm(type, bits)
SignatureAlgorithm
Param | Type |
---|---|
type | String |
bits | Number |
Buffer
signatureAlgorithm._signECDSA(digest) ⇒ Create a ECDSA signature for a given digest
Kind: instance method of SignatureAlgorithm
Internal: used by .sign()
Param | Type |
---|---|
digest | Buffer |
Buffer
signatureAlgorithm.sign(input, key) ⇒ Sign an input with a given key
Kind: instance method of SignatureAlgorithm
Param | Type |
---|---|
input | Buffer |
key | Buffer |
Boolean
signatureAlgorithm._verifyHMAC(signature, input, key) ⇒ Verify an HMAC signature
Kind: instance method of SignatureAlgorithm
Internal: used by .verify()
Param | Type |
---|---|
signature | Buffer |
input | Buffer |
key | Buffer |
Boolean
signatureAlgorithm._verifyRSA(signature, input, key) ⇒ Verify an RSA signature
Kind: instance method of SignatureAlgorithm
Internal: used by .verify()
Param | Type |
---|---|
signature | Buffer |
input | Buffer |
key | Buffer |
Boolean
signatureAlgorithm._verifyECDSA(signature, input, key) ⇒ Verify an ECDSA signature
Kind: instance method of SignatureAlgorithm
Internal: used by .verify()
Param | Type |
---|---|
signature | Buffer |
input | Buffer |
key | Buffer |
Boolean
signatureAlgorithm.verify(signature, input, key) ⇒ Verify a signature against an input & key
Kind: instance method of SignatureAlgorithm
Param | Type |
---|---|
signature | Buffer |
input | Buffer |
key | Buffer |
Object
SignatureAlgorithm.type : SignatureAlgorithm type algorithms NOTE: OpenSSL only signs EC with SHA2 when specifying RSA and using an EC key
Kind: static property of SignatureAlgorithm