How "JAVA" JDK KeyStore is used

Source: Internet
Author: User

How to use KeyStore in Java

public static void Main (String args[]) throws Exception {KeyStore KS = keystore.getinstance ("JKS"); char[] pwd = "112233". T Ochararray (); FileInputStream fis = new FileInputStream ("E:/chiwei.keystore"); Ks.load (FIS, pwd);}
Specific Java calls, referencing the official API

DK in Keytool common commands:

-genkey a default file ". KeyStore" is created in the user's home directory, and a MyKey alias is generated, MyKey contains the user's public key, private key, and certificate
(in the case where the build location is not specified, KeyStore will present the user's system default directory, such as: For Windows XP systems, the C:\Documents and settings\username\ file name ". KeyStore" is generated on the system)
-alias Generating aliases
-keystore Specifies the name of the KeyStore (the resulting types of information will not be in the. keystore file)
-keyalg the algorithm that specifies the key, such as RSA DSA (if you do not specify DSA by default)
-validity specifies how many days to create a certificate validity period
-keysize specifying the key length
-storepass Specify the password for the KeyStore (the password required to get the KeyStore information)
-keypass the password for the specified alias entry (the password for the private key)
-dname Specify certificate owner information such as: "cn= name and last name, ou= organizational unit name, o= organization name, L= City or region name, st= state or province name, c= unit of two-letter country code"
-list Show certificate information in KeyStore keytool-list-v-keystore specify keystore-storepass password
-V Show certificate details in KeyStore
-export Export the certificate specified by the alias to a file Keytool-export-alias the alias you want to export-keystore specify Keystore-file Specify the location of the exported certificate and the certificate name-storepass password
The-file parameter specifies the filename to export to a file
-delete Delete an entry in the KeyStore Keytool-delete-alias specify the-keystore specified keystore-storepass password to be deleted
-printcert View the exported certificate information Keytool-printcert-file YUSHAN.CRT
-KEYPASSWD Modify the specified entry password in the KeyStore Keytool-keypasswd-alias the alias to be modified-keypass old password-new new password-storepass keystore password-keystore sage
-STOREPASSWD Modify KeyStore Password Keytool-storepasswd-keystore e:\yushan.keystore (need to change password KeyStore)-storepass 123456 (original password)- New Yushan (password)
-import the signed digital certificate into the KeyStore Keytool-import-alias specify an alias for the import entry-keystore specify the certificate to be imported Keystore-file

-storetype the type of KeyStore. Commonly used are JKS (default), JCEKS (recommended), Pkcs12,bks,uber. Each keystore can only be one of these types.

The following are the default values for each option.
-alias "MyKey"

-keyalg "DSA"

-keysize 1024

-validity 90

-keystore file named. KeyStore in the user host directory

-file standard input when reading, standard output when writing

Start with the Keytool tool to generate the key


View KeyStore


Export the certificate through the KeyStore generated above


View certificate Information


Now let's prepare a certificate to be imported into the keystore generated above


This adds the tree certificate to Chiwei's KeyStore.


How "JAVA" JDK KeyStore is used

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.