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

28 lines
633 B
JavaScript
Raw Normal View History

2019-10-08 21:13:13 +00:00
'use strict';
2020-07-28 21:53:50 +00:00
module.exports = async function () {
2019-10-24 17:39:25 +00:00
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
});
2020-07-28 21:53:50 +00:00
['kty', 'd', 'n', 'e'].forEach(function (k) {
2019-10-24 17:39:25 +00:00
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();
}