Comparing version 0.1.0 to 0.2.0
"use strict"; | ||
var signer = require("./signer"); | ||
var content = require("./content"); | ||
module.exports = function jwa(alg) { | ||
var match; | ||
var signing = alg.match(/^(HS|RS|ES|none)(256|384|512)?$/); | ||
var keyMgmt = alg.match(/[]/); | ||
var contEnc = alg.match(/[]/); | ||
var contEnc = alg.match(/^A(128|192|256)(CBC|GCM)(-HS(256|384|512))?$/); | ||
if(signing) { | ||
return signer(signing[1], signing[2]); | ||
match = signer(signing[1], signing[2]); | ||
} /*else if(keyMgmt) { | ||
} else if(contEnc) { | ||
}*/ else if(contEnc) { | ||
match = content(contEnc[2], contEnc[1], contEnc[4]); | ||
} | ||
} */else { | ||
if(match) { | ||
return match; | ||
} else { | ||
throw new TypeError("Invalid algorithm"); | ||
} | ||
} |
@@ -5,3 +5,3 @@ "use strict"; | ||
var bufferEqual = require("../bufferEqual"); | ||
var BigNumber = require("asn1.js").bignum; | ||
var BigNumber = require("bn.js"); | ||
var EcdsaSignature = require("asn1.js").define("Ecdsa-Sig-Value", function() { | ||
@@ -8,0 +8,0 @@ this.seq().obj( |
{ | ||
"name": "jose", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "JSON Object Signing and Encryption (JOSE) library (symmetric and asymmetric)", | ||
@@ -36,4 +36,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"asn1.js": "^2.2.0" | ||
"asn1.js": "^2.2.0", | ||
"bn.js": "^3.1.2" | ||
} | ||
} |
@@ -6,4 +6,2 @@ # jose | ||
JSON Object Signing and Encryption (JOSE) library (symmetric and asymmetric) | ||
# API | ||
@@ -16,3 +14,3 @@ ## JWA | ||
The following cryptographic algorithms are supported for JWS: | ||
The following digital signature/MAC algorithms are supported: | ||
@@ -32,7 +30,18 @@ "alg" Header Parameter | Digital Signature or MAC Algorithm | ||
Currently no key encryption and content encryption algorithms are | ||
The following content encryption algorithms are supported: | ||
"enc" Header Parameter | Content Encryption Algorithm | ||
-----------------|----------------------------------------- | ||
A128CBC-HS256 | AES CBC using 128-bit key with SHA-256 as HMAC | ||
A192CBC-HS384 | AES CBC using 192-bit key with SHA-384 as HMAC | ||
A256CBC-HS512 | AES CBC using 256-bit key with SHA-512 as HMAC | ||
A128GCM | AES GCM using 128-bit key | ||
A192GCM | AES GCM using 192-bit key | ||
A256GCM | AES GCM using 256-bit key | ||
Currently no key encryption algorithms are | ||
supported. | ||
### jwa(algorithm) | ||
Creates a new `jwa` object with `sign` and `verify` methods, depending | ||
Creates a new `jwa` object with `sign` and `verify` or `encrypt` and `decrypt` methods, depending | ||
on the specified algorithm. Valid values for `algorithm` can be found | ||
@@ -93,2 +102,40 @@ in the above table and are case-sensitive. Passing an invalid algorithm | ||
console.log(isValid); // Prints 'true' | ||
``` | ||
### jwa.encrypt(plaintext, aad, iv, key) | ||
*This method is only available to algorithms for content encryption.* | ||
Encrypt `plaintext` and compute an authentication tag using `aad`, | ||
`iv` and `key`. | ||
All parameters must be `Buffer`s except `plaintext` which can | ||
also be a `string`. | ||
Returns an object containing `cipher` with the ciphertext and `tag` | ||
with the authentication tag, both being a `Buffer`. | ||
#### Example: | ||
```js | ||
var jose = require('jose'); | ||
var aes = jose.jwa('A256GCM'); | ||
var enc = aes.encrypt('secret', aad, iv, key); | ||
console.log(enc.cipher); // Prints Buffer <5F, ... | ||
console.log(enc.tag); // Prints Buffer <9E, ... | ||
``` | ||
### jwa.decrypt(ciphertext, tag, aad, iv, key) | ||
*This method is only available to algorithms for content encryption.* | ||
Authenticate and decrypt `ciphertext` using `tag`, `aad`, `iv` and `key`. | ||
All parameters must be `Buffer`s. | ||
Returns a `Buffer` containing the decrypted plaintext. Throws an | ||
Error if the `ciphertext` can't be authenticated. | ||
```js | ||
var jose = require('jose'); | ||
var aes = jose.jwa('A256GCM'); | ||
var plain = aes.encrypt(ciphertext, tag, aad, iv, key); | ||
console.log(plain); // Prints Buffer <F9, ... | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28046
17
541
137
2
+ Addedbn.js@^3.1.2
+ Addedbn.js@3.3.0(transitive)