In Java, keytool.exe (located in the JDK \ bin directory) can be used to create a digital certificate. All digital certificates are saved to the certificate library in the form of a one (alias difference, A certificate in the certificate library contains the private key, public key, and information of the certificate. A certificate file in the certificate library can be exported. The certificate file only contains the subject information and the corresponding public key.
1. Generate a key and save it as a certificate file
Keytool-genkey-alias bogus-keysize 512-validity 3650-keyalg RSA-dname "cn = bogus.com, ou = xxx ca, O = bogus Inc, L = Stockholm, S = Stockholm, C = Se "-keypass boguspw-storepass boguspw-keystore Sean. CERT
2. Generate a key
D: \> keytool-genkey-alias Wenger-keysize 1024-keypass abcdef-keystore mykeys
Tore-storepass abcdef-dname "cn = Chen Sr, ou = tanglab, O = lab, L = GZ, St = Gd, c = cn"
3. Export the key and save it as a certificate
D: \> keytool-export-alias Wenger-file mycert. cert-keystore mykeystore-storepass abcdef
Authentication stored in files <mycert. Cert>
JDK Keytool Common commands
-Genkey creates a default file ". keystore" in the user's main directory, and generates a mykey alias. mykey contains the user's public key, private key, and certificate.
-Alias generation
-Keystore specifies the name of the keystore (the generated information will not be in the. keystore file.
-Keyalg specifies the key's Algorithm
-Validity: Specifies the validity period of the created certificate.
-Keysize: Specifies the key length.
-Storepass: password of the specified keystore
-Keypass: Specifies the password of an Alias Entry
-Dname indicates the certificate owner information, for example, "cn = sagely, ou = ASD, O = szu, L = SZ, St = Gd, c = cn"
-List: displays Certificate Information in the keystore. Keytool -List-v-keystore sage-storepass ....
-V: displays the certificate details in the keystore.
-Export: export the Certificate specified by the alias to a file. Keytool -Export-alias caroot-file caroot. CRT
-The file parameter specifies the file name to be exported.
-Delete: delete an entry in the keystore Keytool -Delete-alias sage-keystore sage
-Keypasswd: Modify the entry password specified in the keystore Keytool -Keypasswd-alias sage-keypass ......-New ......-storepass ......-keystore sage
-Import the signed digital certificate to the keystore Keytool -Import-alias sage-keystore sagely-file Sagely. CRT
Import signed digital certificates Keytool -After list-V, you can obviously find that the length of the authentication chain is longer and print all the CA chains.
1. Certificate display
-List
[-V |-RFC] [-alias <alias>]
[-Keystore <keystore>] [-storepass <storepass>]
[-Storetype <storetype>] [-provider <provider_class_name>]
For example: Keytool -List-v-alias rapaserver-keystore cacerts-storepass 12345678
Keytool -List-v-keystore d2aapplet. keystore-storepass 12345678-storetype iaikkeystore
2. Export the certificate to the certificate file
For example: Keytool -Export-keystore monitor. keystore-alias Monitor-File Monitor. Cer
Monitor the certificate library. certificates with the alias monitor in keystore are exported to monitor. the CER Certificate file contains the information of the certificate body and the public key of the certificate, excluding the private key, which can be made public.
Keytool -Export-keystore d2aapplet. keystore-alias rapaserver-file rapa. cert-storetype iaikkeystore
3. Import the keystore to the certificate
Import rapa. Cert to the Java default certificate cacerts
Keytool -Import-alias rapaserver-keystore cacerts-file rapa. cert-keystore cacerts
4. delete a certificate entry
Keytool The command line parameter-delete of can delete entries in the keystore, such:Keytool -Delete
-Alias rapaserver-keystore d2aapplet. keystore: This command deletes the certificate rapaserver in d2aapplet. keystore.
5. Certificate entry password Modification
Use the-keypasswd parameter, for example: Keytool -Keypasswd-alias rapaserver-keystore d2aapplet. keystore: You can interactively modify the entry in the d2aapplet. keystore certificate library as the certificate of rapaserver.
Keytool -The keypasswd-alias rapaserver-keypass 654321-New 123456-storepass 888888-keystore d2aapplet. keystore command line uses non-interactive methods to change the password of the certificate whose alias is rapaserver in the library as the new password.
654321 indicates the original password of the certificate, and 123456 indicates the password of the credential store.