acme.js-ARCHIVED/tests/generate-cert-key.js

28 lines
631 B
JavaScript
Raw Normal View History

2019-10-08 21:13:13 +00:00
'use strict';
2019-10-24 17:39:25 +00:00
module.exports = async function() {
console.log('[Test] can generate, export, and import key');
2019-10-08 21:13:13 +00:00
var Keypairs = require('@root/keypairs');
var certKeypair = await Keypairs.generate({ kty: 'RSA' });
2019-10-24 17:39:25 +00:00
//console.log(certKeypair);
2019-10-08 21:13:13 +00:00
var pem = await Keypairs.export({
jwk: certKeypair.private,
encoding: 'pem'
});
2019-10-24 17:39:25 +00:00
var jwk = await Keypairs.import({
pem: pem
});
['kty', 'd', 'n', 'e'].forEach(function(k) {
if (!jwk[k] || jwk[k] !== certKeypair.private[k]) {
throw new Error('bad export/import');
}
});
//console.log(pem);
console.log('PASS');
};
2019-10-08 21:13:13 +00:00
2019-10-24 17:39:25 +00:00
if (require.main === module) {
module.exports();
}