Hello., I have id_rsa.pub key generated by ssh-keygen. I need to prigrammically convert id_rsa.pub to RSA DER formatted key.
How it is possible? Preferably ruby language but I would be glad for algorythm in any language.
Hello., I have id_rsa.pub key generated by ssh-keygen. I need to prigrammically convert id_rsa.pub to RSA DER formatted key.
How it is possible? Preferably ruby language but I would be glad for algorythm in any language.
If you use ssh-keygen to generate a key:
$ ssh-keygen
Then you can just use openssl to pull out the public key and write it in the DER format like this:
$ openssl rsa -in id_rsa -out pub.der -outform DER -pubout
writing RSA key
You can view the DER output as PEM like this:
$ openssl rsa -in pub.der -inform DER -pubin -text
I don't use Ruby, so I don't know how easy it is to use OpenSSL from Ruby.
Edit: I answered too quickly -- you wrote id_rsa.pub and you may not have the id_rsa itself. Another Stack Overflow question is for the reverse conversion, but the source code found there might help: Convert pem key to ssh-rsa format Once you have PEM you can use openssl to conver the PEM to DER.