2

There have seen a number of similar question,but none exactly like mine. The given answers have not worked for me. I wanted to add a private ssh key to a java keystore in command line and later retrive it in java code.

I have generated the ssh keys in the following way :

ssh-keygen -t rsa -b 4096 -C "abc@xyz.com"

That gives me 2 key file. 'id_rsa' and 'id_rsa.pub' i.e the public and private key

I want to store just the private key i.e. 'id_rsa' into the java keystore using the keytool command line tool.

I am trying something like this.

openssl pkcs12 -export -inkey key  -in key.pub -out identity.p12 -name alias1 -nocerts

keytool -importkeystore -deststorepass "password1" -destkeypass "password2" -destkeystore ~/jks/keystore1.jks -srckeystore /tmp/keys/identity.p12 -srcstoretype PKCS12 -srcstorepass "pass" -alias "alias1"

But that gives me 'keytool error: java.lang.NullPointerException: invalid null input'

Please guide me on the best way to achieve this.

Navin Desai
  • 21
  • 1
  • 2
  • Possible duplicate: http://stackoverflow.com/questions/31385944/how-to-add-ssh-identity-file-keypair-to-jks-keystore – Mike Apr 20 '17 at 17:37
  • I have already seen that, but in that solution, I do not know where the example.req comes from ? It says to do something like : openssl x509 -signkey id_rsa -req -in example.req – Navin Desai Apr 21 '17 at 08:37
  • Looks like he created a certificate prior to that, and used that to wrap the ssh key. He just skipped the steps prior to that. Here's a site that shows you the Certificate Signing Request steps, https://www.sslshopper.com/article-most-common-openssl-commands.html – Mike Apr 21 '17 at 14:00
  • Thanks Mike. I will try this. – Navin Desai Apr 21 '17 at 16:09

0 Answers0