I have id_rsa.pub key generated by ssh-keygen.
How can I programmatically convert id_rsa.pub files to RSA DER formatted keys?
I have id_rsa.pub key generated by ssh-keygen. How can I programmatically convert id_rsa.pub files
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you use ssh-keygen to generate a key:
Then you can just use openssl to pull out the public key and write it in the DER format like this:
You can view the DER output as PEM like this:
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 convert the PEM to DER.
Edit, May 2014: Ruby has become my favorite programming language, and the original question (since edited) asked about Ruby. Here is code to read the id_rsa.pub (public key) and write an OpenSSL-generated, DER-formatted public key:
You can check the output with these openssl commands in the shell: