2016-07-30 23:09:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var RSA = require('../').RSA;
|
|
|
|
|
2016-07-31 03:47:52 +00:00
|
|
|
RSA.generateKeypair(null, null, null, function (err, keys) {
|
2016-07-30 23:09:37 +00:00
|
|
|
if (!keys.privateKeyJwk) {
|
|
|
|
throw new Error("Expected privateKeyJwk, but it is missing");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
keys.publicKeyJwk
|
|
|
|
|| keys.privateKeyPem
|
|
|
|
|| keys.publicKeyPem
|
|
|
|
|| keys.thumbprint
|
|
|
|
|| keys._ursa
|
|
|
|
|| keys._forge
|
|
|
|
) {
|
2016-08-01 08:03:50 +00:00
|
|
|
console.error(Object.keys(keys));
|
2016-07-30 23:09:37 +00:00
|
|
|
throw new Error("Got unexpected keys");
|
|
|
|
}
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
public: true // export public keys
|
|
|
|
, pem: true // export pems
|
|
|
|
, jwk: false // export jwks
|
|
|
|
, internal: true // preserve internal intermediate formats (_ursa, _forge)
|
2016-08-01 08:03:50 +00:00
|
|
|
//, thumbprint: true // JWK sha256 thumbprint
|
2016-07-30 23:09:37 +00:00
|
|
|
};
|
2016-07-31 03:47:52 +00:00
|
|
|
RSA.generateKeypair(512, 65537, options, function (err, keys) {
|
|
|
|
if (
|
2016-08-01 08:03:50 +00:00
|
|
|
(keys.publicKeyJwk && !keys.thumbprint)
|
|
|
|
|| !keys.privateKeyPem
|
|
|
|
|| !keys.publicKeyPem
|
|
|
|
//|| !keys.thumbprint
|
|
|
|
|| !(keys._ursa || keys._forge)
|
2016-07-31 03:47:52 +00:00
|
|
|
) {
|
2016-08-01 08:03:50 +00:00
|
|
|
console.error(Object.keys(keys));
|
|
|
|
throw new Error("Missing expected keys");
|
2016-07-31 03:47:52 +00:00
|
|
|
}
|
2016-08-01 08:03:50 +00:00
|
|
|
|
|
|
|
console.log('All is well!');
|
2016-07-30 23:09:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|