Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate private and public key file using keytool

I want to know if there is a way to create .key file for (public and private key) using keytool , I understand that we can generate a keystore using below command

keytool -genkeypair -keysize 2048 -keyalg RSA -alias appalias -keystore D:\..\..

which has the keypair , I am also aware of java way of retrieving the keys from keystore , but is there a direct way for it using KEYTOOL

like image 413
user3185729 Avatar asked Sep 30 '15 13:09

user3185729


2 Answers

It's possible to extract the public keys using keytool, check this link.

Export/import commands We'll use the keytool -export command to extract the public key into a file, and then use the keytool -import command to insert it into a new keystore. Here's the command to extract the client's public key:

keytool -export -alias clientprivate -keystore client.private -file temp.key -storepass clientpw

And here's the command to insert the client's private key into its own keystore:

keytool -import -noprompt -alias clientpublic -keystore client.public -file temp.key -storepass public

We'll also extract and store the server's public key. Here's the command to extract the key:

keytool -export -alias serverprivate -keystore server.private -file temp.key -storepass serverpw

And here's the command to place it in its own keystore:

keytool -import -noprompt -alias serverpublic -keystore server.public -file temp.key -storepass public
like image 126
Krishnaraj Avatar answered Nov 18 '22 20:11

Krishnaraj


As per the findings there is no direct way to extract the private key out of the keystore , this link How can I export my private key from a Java Keytool keystore? helped to me extract the keys , it requires OpenSSL but i think thats the only way to go.

like image 30
user3185729 Avatar answered Nov 18 '22 19:11

user3185729