Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ssh public keys from various formats to Open SSH with node-forge

I'd like to convert ssh public keys provided in various formats into the Open SSH format using node-forge.

I have no problem generating the keys and converting with:

forge.ssh.publicKeyToOpenSSH(key, comment);

but cannot figure out how to read the files into node-forge, Tried:

pki.publicKeyFromPem(pem);

or

pki.publicKeyFromAsn1(subjectPublicKeyInfo);
like image 519
Ian A. Avatar asked Jan 30 '26 22:01

Ian A.


1 Answers


You can load OpenSSL public keys (PKCS#8) like this:

var forgePubKey = forge.pki.publicKeyFromPem('-----BEGIN PUBLIC KEY-----' + publicKey + '-----END PUBLIC KEY-----');

where publicKey is BASE64 encoded

like image 82
dtrenin Avatar answered Feb 02 '26 18:02

dtrenin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!