Java Keytool Use of detailed

Source: Internet
Author: User
Tags dname rfc sha1 asymmetric encryption

Keytool is a Java Data Certificate management tool that keytool the key (key) and certificate (certificates) in a file called KeyStore in KeyStore, containing two kinds of data:
Key Entity--key (secret key) or private key and paired public key (with asymmetric encryption)
Trusted certificate Entity (trusted certificate entries)--only public key is included

Ailas (alias) Each keystore is associated with this unique alias, which is usually case-insensitive

keytool Common commands in JDK:
-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.

-alias "MyKey"
-keyalg "DSA"
-keysize 1024x768
-validity
-keystore User host directory named. keystore Files
-file Read as standard input, write as standard output

Staged build:
Keytool -genkey -alias Yushan (alias)-keypass Yushan (alias password)-keyalg RSA (algorithm)-keysize 1024 (key length)-validity 365 (validity, days units)-keyst Ore
E:\yushan.keystore (Specify the location and certificate name of the generated certificate)-storepass 123456 (Obtain the password for the KeyStore information); Enter the relevant information;
One-time generation:
Keytool- Genkey-alias yushan-keypass yushan-keyalg rsa-keysize 1024-validity 365-keystore e:\yushan.keystore-storepass 12345 6-dname "cn= (first name with
Last name), ou= (organizational unit name), o= (organization name), L= (city or region name), st= (state or province name), c= (two-letter country code for unit)";(in English)
2, KeyStore information:
Keytool-list-v -keystore e:\keytool\ Yushan.keystore-storepass 123456

Keytool-list-v-keystore D:\Desktop\cloud-mobile-pushconsole\cloud-mobile-pushconsole\certificate\cer1\ Mysearch-push-product.p12-storepass 123456

Display content:
---------------------------------------------------------------------
Keystore Type: JKS
Keystore by: SUN

Your keystore contains 1 inputs

Alias Name: Yushan
Date Created: 2009-7-29
Item Type: Privatekeyentry
Certification Chain Length: 1
Certification [1]:
Owner: Cn=yushan, ou=xx Company, O=xx Association, l= Xiangtan, st= Hunan, c= China
Issuer: Cn=yushan, ou=xx Company, O=xx Association, l= Xiangtan, st= Hunan, c= China
Serial Number: 4a6f29ed
Validity: Wed Jul 00:40:13 CST 2009 to Thu Jul 00:40:13 CST 2010
Certificate thumbprint:
Md5:a3:d7:d9:74:c3:50:7d:10:c9:c2:47:b0:33:90:45:c3
Sha1:2b:fc:9e:3a:df:c6:c4:fb:87:b8:a0:c6:99:43:e9:4c:4a:e1:18:e8
Signature Algorithm Name: Sha1withrsa
Version: 3
--------------------------------------------------------------------

By default, the-list command prints the MD5 thumbprint of the certificate. If the-v option is specified, the certificate is printed in a readable format, and if the-RFC option is specified, the certificate is output in printable encoding format.

Keytool -list-rfc -keystore e:\yushan.keystore-storepass 123456

Show:

-------------------------------------------------------------------------------------------------------

Keystore Type: JKS
Keystore by: SUN

Your keystore contains 1 inputs

Alias Name: Yushan
Date Created: 2009-7-29
Item Type: Privatekeyentry
Certification Chain Length: 1
Certification [1]:
-----BEGIN CERTIFICATE-----
Miicszccabsgawibagiesm8p7tanbgkqhkig9w0baqufadbqmq8wdqydvqqgdabkuk3lm70xdzan
Bgnvbagmbua5luwnlzepma0ga1uebwwg5rmy5r2tmrewdwydvqqkdah4eownj+s8mjerma8ga1ue
Cwwiehjlhazlj7gxdzanbgnvbamtbnl1c2hhbjaefw0wota3mjgxnjqwmtnafw0xmda3mjgxnjqw
mtnamgoxdzanbgnvbaymbus4rewbvtepma0ga1uecawg5rmw5y2xmq8wdqydvqqhdabmuzjmva0x
Etapbgnvbaomchh45y2p5lyamrewdwydvqqldah4eowfrowpudepma0ga1ueaxmgexvzagfumigf
Ma0gcsqgsib3dqebaquaa4gnadcbiqkbgqcjoru1rqczrztnbwxefvnspqbyks220rs8y/ox3mza
Hjl4wlfourzuuxxuvqr2jx7qi+xkme+dhqj9r6aaclbci/t1jwf8mvyxtprutze/6kezdhowee70
Liwlve+hytlbhz03zhwcd6q5humu27du3mpqvqiwzty7mrwivqq8iqidaqabma0gcsqgsib3dqeb
Bquaa4gbagoqq1/fntfkpqh+ni6h3fzdn3sr8zzdmboaiyvlahbb85xdj8qztarhbzmjcidhxal1
I08ct3e8u87v9t8gzfwvc4bfg/+zefev76sfpve56ix7p1jpsu78z0m69hhlds77vjtdyfmsvtxv
Syhp3fxfzx9wyhipbwd8vpk/ngep
-----END CERTIFICATE-----

-------------------------------------------------------------------------------------------------------

3, the export of certificates:

Keytool-export-alias yushan-keystore e:\yushan.keystore-file e:\yushan.crt (Specify the exported certificate location and certificate name)-storepass 123456

4. View the exported certificate information
Keytool-printcert-file YUSHAN.CRT
Display: (under Windows you can double-click yushan.crt to view)
-----------------------------------------------------------------------
Owner: Cn=yushan, ou=xx Company, O=xx Association, l= Xiangtan, st= Hunan, c= China
Issuer: Cn=yushan, ou=xx Company, O=xx Association, l= Xiangtan, st= Hunan, c= China
Serial Number: 4a6f29ed
Validity: Wed Jul 00:40:13 CST 2009 to Thu Jul 00:40:13 CST 2010
Certificate thumbprint:
Md5:a3:d7:d9:74:c3:50:7d:10:c9:c2:47:b0:33:90:45:c3
Sha1:2b:fc:9e:3a:df:c6:c4:fb:87:b8:a0:c6:99:43:e9:4c:4a:e1:18:e8
Signature Algorithm Name: Sha1withrsa
Version: 3
-----------------------------------------------------------------------

5, the import of certificates:
To prepare an imported certificate:
Keytool-genkey-alias shuany-keypass shuany-keyalg rsa-keysize 1024-validity 365-keystore e:\shuany.keystore-storep 123456-dname "Cn=shuany,

Ou=xx, O=xx, L=xx, st=xx, c=xx ";
Keytool-export-alias Shuany-keystore e:\shuany.keystore-file E:\shuany.crt-storepass 123456

Now add the SHUANY.CRT to the Yushan.keystore:
Keytool-import-alias Shuany (Specifies the alias of the import certificate, if you do not specify the default is MyKey, the alias is unique, otherwise the import error)-file E:\shuany.crt-keystore E:\yushan.keystore-storepass

123456

Keytool-list-v-keystore E:\keytool\yushan.keystore-storepass 123456
Show:
------------------------------------------------------------------------------
Keystore Type: JKS
Keystore by: SUN

Your keystore contains 2 inputs

Alias Name: Yushan
Date Created: 2009-7-29
Item Type: Privatekeyentry
Certification Chain Length: 1
Certification [1]:
Owner: Cn=yushan, ou=xx Company, O=xx Association, l= Xiangtan, st= Hunan, c= China
Issuer: Cn=yushan, ou=xx Company, O=xx Association, l= Xiangtan, st= Hunan, c= China
Serial Number: 4a6f29ed
Validity: Wed Jul 00:40:13 CST 2009 to Thu Jul 00:40:13 CST 2010
Certificate thumbprint:
Md5:a3:d7:d9:74:c3:50:7d:10:c9:c2:47:b0:33:90:45:c3
Sha1:2b:fc:9e:3a:df:c6:c4:fb:87:b8:a0:c6:99:43:e9:4c:4a:e1:18:e8
Signature Algorithm Name: Sha1withrsa
Version: 3


*******************************************
*******************************************


Alias Name: Shuany
Date Created: 2009-7-29
INPUT type: trustedcertentry

Owner: Cn=shuany, Ou=xx, O=xx, L=xx, St=xx, c=xx
Issued by: Cn=shuany, Ou=xx, O=xx, L=xx, St=xx, c=xx
Serial Number: 4A6F2CD9
Validity: Wed Jul 00:52:41 CST 2009 to Thu Jul 00:52:41 CST 2010
Certificate thumbprint:
Md5:15:03:57:9b:14:bd:c5:50:21:15:47:1e:29:87:a4:e6
Sha1:c1:4f:8b:cd:5e:c2:94:77:b7:42:29:35:5c:bb:bb:2e:9e:f0:89:f5
Signature Algorithm Name: Sha1withrsa
Version: 3


*******************************************
*******************************************
------------------------------------------------------------------------------

6, the deletion of the certificate entry:
Keytool-delete-alias Shuany (Specify the alias to be removed)-keystore Yushan.keystore-storepass 123456

7, the Certificate entry password modification:
Keytool-keypasswd-alias Yushan (alias to change password)-keypass Yushan (original password)-new 123456 (new password for alias)-keystore E:\yushan.keystore-storepass 123456

8, KeyStore password changes:
Keytool-storepasswd-keystore E:\yushan.keystore (need to change password KeyStore)-storepass 123456 (original password)-new Yushan (new password)

9. Modify the information of alias Yushan in KeyStore

Keytool -selfcert -alias yushan-keypass yushan-keystore e:\yushan.keystore-storepass 123456-dname "Cn=yushan , Ou=yushan,o=yushan,c=us "

Java Keytool Use of detailed

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.