Reputation: 1075
I'm creating a AWS KMS nock version and specifically working on getPublicKey. Here, I need to create a DER-encoded public key. Is there a Node.js way to do this? Thanks.
Upvotes: 0
Views: 186
Reputation: 1075
KeyUsage === 'ENCRYPT_DECRYPT'
? // eslint-disable-next-line no-sync
crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'der'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'der',
cipher: 'aes-256-cbc',
passphrase: 'passphrase'
}
})
: // eslint-disable-next-line no-sync
crypto.generateKeyPairSync('ec', {
namedCurve: 'P-256',
publicKeyEncoding: {
type: 'spki',
format: 'der'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'der',
cipher: 'aes-256-cbc',
passphrase: 'passphrase'
}
});
Upvotes: 0