mirror of
https://github.com/danbulant/jose
synced 2026-05-24 20:41:46 +00:00
20 lines
662 B
JavaScript
20 lines
662 B
JavaScript
const { generateKeyPairSync } = require('crypto')
|
|
|
|
const { keyObjectSupported } = require('../../lib/help/runtime_support')
|
|
const { createPublicKey, createPrivateKey } = require('../../lib/help/key_object')
|
|
|
|
module.exports = {
|
|
generateKeyPairSync (type, options) {
|
|
if (keyObjectSupported) {
|
|
return generateKeyPairSync(type, options)
|
|
}
|
|
|
|
const { privateKey, publicKey } = generateKeyPairSync(type, {
|
|
publicKeyEncoding: { type: 'spki', format: 'pem' },
|
|
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
|
|
...options
|
|
})
|
|
|
|
return { privateKey: createPrivateKey(privateKey), publicKey: createPublicKey(publicKey) }
|
|
}
|
|
}
|