I am on node version: v10.14.1 and I generate keyPairs with this code:
generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: ''
}
}, (err, publicKey, privateKey) => {
// Do stuff
});
This will create a public key in this format:
-----BEGIN RSA PUBLIC KEY-----
...
-----END RSA PUBLIC KEY-----
Unfortunately sometimes different formats are needed. In my case to upload public key to AWS the OpenSSH format is needed which I believe is something like this:
ssh-rsa
...
How can I either convert the RSA public key format to OpenSSH format or generate it directly with generateKeyPair()
?