Class Index | File Index

Classes


Class KJUR.jws.JWSJS


Version 2.1.0 (2016 Sep 6).
JSON Web Signature JSON Serialization (JWSJS) class
Defined in: jwsjs-2.0.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
JSON Web Signature JSON Serialization (JWSJS) class.
Field Summary
Field Attributes Field Name and Description
 
array of Encoded JWS Headers
 
array of Encoded JWS signature value
 
Encoded JWS payload
Method Summary
Method Attributes Method Name and Description
 
addSignature(alg, spHead, key, pass)
add a signature to existing JWS-JS by algorithm, header and key.
 
get JSON object for this JWS-JS object.
 
init()
(re-)initialize this object.
 
(re-)initialize and set first signature with JWS.
 
check if this JWS-JS object is empty.
 
readJWSJS(spJWSJS)
read JWS-JS string or object
NOTE: Loading from JSON object is suppored from jsjws 2.1.0 jsrsasign 5.1.0 (2016-Sep-06).
 
verifyAll(aKeyAlg)
verify all signature of JWS-JS object by array of key and acceptAlgs.
 
verifyNth(idx, key, acceptAlgs)
verify Nth signature of JWS-JS object by key and acceptAlgs.
Class Detail
KJUR.jws.JWSJS()
JSON Web Signature JSON Serialization (JWSJS) class.
This class generates and verfies "JSON Web Signature JSON Serialization (JWSJS)" of IETF Internet Draft. Here is major methods of this class:
Author: Kenji Urushima.
// initialize
jwsjs1 = new KJUR.jws.JWSJS();
jwsjs1.readJWSJS("{headers: [...], payload: "eyJ...", signatures: [...]}");

// add PS256 signature with RSA private key object
prvKeyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...");
jwsjs1.addSignature("PS256", {alg: "PS256"}, prvKeyObj);
// add HS256 signature with HMAC password "secret"
jwsjs1.addSignature(null, {alg: "HS256"}, {utf8: "secret"});

// get result finally
jwsjsObj1 = jwsjs1.getJSON();

// verify all signatures
isValid = jwsjs1.verifyAll([["-----BEGIN CERT...", ["RS256"]],
                            [{utf8: "secret"}, ["HS256"]]]);
See:
old jwjws home page https://kjur.github.io/jsjws/
'jwrsasign'(RSA Sign JavaScript Library) home page https://kjur.github.io/jsrsasign/
IETF I-D JSON Web Signature JSON Serialization (JWS-JS) specification
Field Detail
{array of String} aHeader
array of Encoded JWS Headers

{array of String} aSignature
array of Encoded JWS signature value

{String} sPayload
Encoded JWS payload
Method Detail
addSignature(alg, spHead, key, pass)
add a signature to existing JWS-JS by algorithm, header and key.
// initialize
jwsjs1 = new KJUR.jws.JWSJS();
jwsjs1.readJWSJS("{headers: [...], payload: "eyJ...", signatures: [...]}");

// add PS256 signature with RSA private key object
prvKeyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...");
jwsjs1.addSignature("PS256", {alg: "PS256"}, prvKeyObj);

// add HS256 signature with HMAC password "secret"
jwsjs1.addSignature(null, {alg: "HS256"}, {utf8: "secret"});

// get result finally
jwsjsObj1 = jwsjs1.getJSON();
Parameters:
{String} alg
JWS algorithm. If null, alg in header will be used.
{Object} spHead
string or object of JWS Header to add.
{Object} key
JWS key to sign. key object, PEM private key or HMAC key
{String} pass
optional password for encrypted PEM private key

getJSON()
get JSON object for this JWS-JS object.
jwsj1 = new KJUR.jws.JWSJS();
// do some jwsj1 operation then get result by getJSON()
jwsjsObj1 = jwsjs1.getJSON();
// jwsjsObj1 → { headers: [...], payload: "ey...", signatures: [...] }

init()
(re-)initialize this object.

initWithJWS(sJWS)
(re-)initialize and set first signature with JWS.
jwsjs1 = new KJUR.jws.JWSJWS();
jwsjs1.initWithJWS("eyJ...");
Parameters:
{String} sJWS
JWS signature to set

isEmpty()
check if this JWS-JS object is empty.
Returns:
1 if there is no signatures in this object, otherwise 0.

readJWSJS(spJWSJS)
read JWS-JS string or object
NOTE: Loading from JSON object is suppored from jsjws 2.1.0 jsrsasign 5.1.0 (2016-Sep-06).
// load JWSJS from string
jwsjs1 = new KJUR.jws.JWSJS();
jwsjs1.readJWSJS("{headers: [...], payload: "eyJ...", signatures: [...]}");

// load JWSJS from JSON object
jwsjs1 = new KJUR.jws.JWSJS();
jwsjs1.readJWSJS({headers: [...], payload: "eyJ...", signatures: [...]});
Parameters:
{Object} spJWSJS
string or JSON object of JWS-JS to load.

verifyAll(aKeyAlg)
verify all signature of JWS-JS object by array of key and acceptAlgs.
jwsjs1 = new KJUR.jws.JWSJS();
jwsjs1.readJWSJS("{headers: [...], payload: "eyJ...", signatures: [...]}");
isValid = jwsjs1.verifyAll([["-----BEGIN CERT...", ["RS256"]],
                            [{utf8: "secret"}, ["HS256"]]]);
Parameters:
{array of key and acceptAlgs} aKeyAlg
a array of key and acceptAlgs
Since:
jwsjs 2.1.0 jsrsasign 5.1.0
Returns:
true if all signatures are valid otherwise false

verifyNth(idx, key, acceptAlgs)
verify Nth signature of JWS-JS object by key and acceptAlgs.
jwsjs1 = new KJUR.jws.JWSJS();
jwsjs1.readJWSJS("{headers: [...], payload: "eyJ...", signatures: [...]}");
isValid1 = jwsjs1.verifyNth(0, "-----BEGIN CERT...", ["RS256"]);
isValid2 = jwsjs1.verifyNth(1, {utf8: "secret"}, ["HS256"]);
Parameters:
{Integer} idx
nth index of JWS-JS signature to verify
{Object} key
key to verify
{array of String} acceptAlgs
array of acceptable signature algorithms
Since:
jwsjs 2.1.0 jsrsasign 5.1.0
Returns:
true if signature is valid otherwise false

© 2012-2017 Kenji Urushima, All rights reserved
Documentation generated by JsDoc Toolkit 2.4.0