document signJws
This commit is contained in:
parent
77d2d6daa6
commit
2541ca8a9f
50
README.md
50
README.md
|
@ -67,6 +67,7 @@ API
|
|||
* `RSA.exportPublicPem(keypair)`
|
||||
* `RSA.exportPrivateJwk(keypair)`
|
||||
* `RSA.exportPublicJwk(keypair)`
|
||||
* `RSA.signJws(keypair, payload, nonce)`
|
||||
|
||||
`keypair` can be any object with any of these keys `publicKeyPem, privateKeyPem, publicKeyJwk, privateKeyJwk`
|
||||
|
||||
|
@ -94,3 +95,52 @@ RSA.generateKeypair(1024, 65537, { pem: false, public: false, internal: false },
|
|||
, fingerprint: false // NOT IMPLEMENTED (RSA key fingerprint)
|
||||
}
|
||||
```
|
||||
|
||||
### RSA.export*(keypair)
|
||||
|
||||
You put in an object like `{ privateKeyPem: '...' }` or `{ publicKeyJwk: {} }`
|
||||
and you get back the keys in the format you requested.
|
||||
|
||||
Note:
|
||||
|
||||
* Private keys **can** be used to export both private and public keys
|
||||
* Public keys can **NOT** be used to generate private keys
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var keypair = { privateKeyPem: '...' };
|
||||
|
||||
keypair.publicKeyJwk = RSA.exportPublicJwk(keypair);
|
||||
|
||||
console.log(keypair);
|
||||
```
|
||||
|
||||
### RSA.signJws(keypair, payload, nonce)
|
||||
|
||||
Generates a signature in JWS format.
|
||||
|
||||
```javascript
|
||||
var message = "Hello, World!"
|
||||
var nonce = crypto.randomBytes(16).toString('hex');
|
||||
var jws = RSA.signJws(keypair, message, nonce);
|
||||
|
||||
console.log(jws);
|
||||
```
|
||||
|
||||
The result looks like this:
|
||||
|
||||
```javascript
|
||||
{ "header": {
|
||||
"alg": "RS256",
|
||||
"jwk": {
|
||||
"kty": "RSA",
|
||||
"n": "AMJubTfOtAarnJytLE8fhNsEI8wnpjRvBXGK/Kp0675J10ORzxyMLqzIZF3tcrUkKBrtdc79u4X0GocDUgukpfkY+2UPUS/GxehUYbYrJYWOLkoJWzxn7wfoo9X1JgvBMY6wHQnTKvnzZdkom2FMhGxkLaEUGDSfsNznTTZNBBg9",
|
||||
"e": "AQAB"
|
||||
}
|
||||
},
|
||||
"protected": "eyJub25jZSI6IjhlZjU2MjRmNWVjOWQzZWYifQ",
|
||||
"payload": "JLzF1NBNCV3kfbJ5sFaFyX94fJuL2H-IzaoBN-ciiHk",
|
||||
"signature": "Wb2al5SDyh5gjmkV79MK9m3sfNBBPjntSKor-34BBoGwr6n8qEnBmqB1Y4zbo-5rmvsoPmJsnRlP_hRiUY86zSAQyfbisTGrGBl0IQ7ditpkfYVm0rBWJ8WnYNqYNp8K3qcD7NW72tsy-XoWEjNlz4lWJeRdEG2Nt4CJgnREH4Y"
|
||||
}
|
||||
```
|
||||
|
|
4
node.js
4
node.js
|
@ -126,7 +126,9 @@ function create(deps) {
|
|||
|
||||
return sig64;
|
||||
};
|
||||
RSA.generateSignatureJwk = function (keypair, payload, nonce) {
|
||||
|
||||
RSA.signJws = RSA.generateJws = RSA.generateSignatureJws = RSA.generateSignatureJwk =
|
||||
function (keypair, payload, nonce) {
|
||||
keypair = RSA._internal.import(keypair);
|
||||
keypair = RSA._internal.importForge(keypair);
|
||||
keypair.publicKeyJwk = RSA.exportPublicJwk(keypair);
|
||||
|
|
|
@ -45,7 +45,7 @@ var forgeResult = {
|
|||
};
|
||||
*/
|
||||
|
||||
var jws = RSA.generateSignatureJwk(
|
||||
var jws = RSA.signJws(
|
||||
keypair
|
||||
, new Buffer('24bcc5d4d04d095de47db279b05685c97f787c9b8bd87f88cdaa0137e7228879', 'hex')
|
||||
, '8ef5624f5ec9d3ef'
|
||||
|
|
Loading…
Reference in New Issue