rsa-compat.js/tests/generate-key.js

55 lines
1.2 KiB
JavaScript

'use strict';
var RSA = require('../').RSA;
console.log('RSA');
console.log(RSA);
RSA.generateKeypair(null, null, null, function (err, keys) {
console.log('');
console.log('keys');
console.log(keys);
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
) {
console.error(keys);
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)
, thumbprint: true // JWK sha256 thumbprint
};
RSA.generateKeypair(512, 65537, options, function (err, keys) {
console.log('');
console.log('keys');
console.log(keys);
if (
keys.publicKeyJwk
|| keys.privateKeyPem
|| keys.publicKeyPem
|| keys.thumbprint
|| keys._ursa
|| keys._forge
) {
console.error(keys);
throw new Error("Got unexpected keys");
}
});
});