Saturday, March 24, 2018

In this blog I m gonna describe commonly used keytool commands.

######################
TO print the key
######################

keytool -list -v -keystore keystore_public.jks
keytool -list -v -keystore  UIDAIFilesDeviceKey.jks


##################################
-----------IMPORT-----------------
##################################


keytool -importkeystore -srckeystore devicekey31012017_125834.jks -destkeystore keystore.p12 -deststoretype PKCS12 -srcalias DeviceKey -deststorepass 341256 -destkeypass 341256 -storepass 341256


###########################################
-----------------EXPORT--------------
###########################################
- Exporting to the certificate.

keytool -export -alias DeviceKey -keystore home\DeviceKey.jks -rfc -file DeviceKey-public.cert -storepass storepass -keypass keypassword


###############################################
-------------PRINT THE CERTIFICATE------------
###############################################
  keytool -printcert -file  DeviceKey-public.cert



#############How to import from certificate to keystore###############

keytool -importcert -file DeviceKey-public.cert  -keystore keystore.jks -alias "DeviceKey1"

###############################################


 ##########################
 SELF SIGN THE CERTIFICATE using PUBLIC KEY
 ############################
keytool -import -alias certificatekey -file DeviceKey-public.cert -keystore server.truststore  -storepass mmm@123 -noprompt


 #############How to import from certificate to keystore###############

keytool -importcert -file DeviceKey-public.cert  -keystore keystore.jks -alias "DeviceKey1"

 ##############################################################



#############################################################################
           Create a certificate file from a private key
#############################################################################


$ keytool -genkey -alias KeyForPaul -keystore JohnsPrivateKey.store

Enter keystore password:  ABC123
What is your first and last name?
  [Unknown]:  John Doe
What is the name of your organizational unit?
  [Unknown]:  Software Development
What is the name of your organization?
  [Unknown]:  example.com
What is the name of your City or Locality?
  [Unknown]:  Talkeetna
What is the name of your State or Province?
  [Unknown]:  AK
What is the two-letter country code for this unit?
  [Unknown]:  US
Is CN=John Doe, OU=Software Development, O=example.com, L=Talkeetna, ST=AK, C=US correct?
  [no]:  yes

Enter key password for <KeyForPaul>
      (RETURN if same as keystore password):  123XYZ
   
Now that the file JohnsPrivateKey.store is created,
 and the alias "KeyForPaul" has been created, John will export a
 #########
 certificate file from this private keystore, like this:
 #######
     
$ keytool -export -alias KeyForPaul -file certfile.cer -keystore JohnsPrivateKey.store

Enter keystore password:  ABC123
Certificate stored in file <certfile.cer>    

#########################################################################


#################################################################
 Java keytool - import a public key certificate into your keystore
 #################################################################

 keytool -import -alias PublicKeyFromJohn -file certfile.cer -keystore MyPublicKey.store


##################################################################