下面的内容是从windows 控制台复制出来的,
做的事情是:
- 创建一个keystore my.keystore,其中包含一个别名为my1stcert的证明书;
- 然后导出该证明书到my1stcert.cer文件;
- 查看证明书文件的内容;
- 再将文件my1stcert.cer导入到my.keystore中,其别名为my2ndcert;
- 查看keystore的内容。
最终,my.keystore中存放了两个证明书,他们是一样的,但是别名不一样。
D:/j2sdk1.4.2_11/bin>keytool.exe -genkey -alias my1stcert -keystore my.keystore -storepass "yechao" -keypass "yechao" -keyalg "RSA"
What is your first and last name?
[Unknown]: Ye Chao
What is the name of your organizational unit?
[Unknown]: 3k
What is the name of your organization?
[Unknown]: rits
What is the name of your City or Locality?
[Unknown]: shanghai
What is the name of your State or Province?
[Unknown]: shanghai
What is the two-letter country code for this unit?
[Unknown]: zh
Is CN=Ye Chao, OU=3k, O=rits, L=shanghai, ST=shanghai, C=zh correct?
[no]: yes
D:/j2sdk1.4.2_11/bin>keytool.exe -export -alias my1stcert -keystore my.keystore -file my1cert.cer
Enter keystore password: yechao
Certificate stored in file <my1cert.cer>
D:/j2sdk1.4.2_11/bin>keytool.exe -printcert -file my1cert.cer
Owner: CN=Ye Chao, OU=3k, O=rits, L=shanghai, ST=shanghai, C=zh
Issuer: CN=Ye Chao, OU=3k, O=rits, L=shanghai, ST=shanghai, C=zh
Serial number: 4695a81f
Valid from: Thu Jul 12 12:03:43 GMT+08:00 2007 until: Wed Oct 10 12:03:43 GMT+08:00 2007
Certificate fingerprints:
MD5: F8:8E:3E:41:59:8A:34:F5:DF:0F:4B:DE:37:EB:87:1F
SHA1: 8C:D1:B0:50:9B:2C:1D:E9:D5:1C:CF:51:F0:8B:CA:DF:1D:8D:AD:DF
D:/j2sdk1.4.2_11/bin>keytool.exe -import -alias my2ndcert
Enter keystore password: keytool error: java.lang.NullPointerException
D:/j2sdk1.4.2_11/bin>keytool.exe -import -alias my2ndcert -file my1stcert.cer -keystore my.keystore
Enter keystore password: yechao
Owner: CN=Ye Chao, OU=3k, O=rits, L=shanghai, ST=china, C= ZH
Issuer: CN=Ye Chao, OU=3k, O=rits, L=shanghai, ST=china, C= ZH
Serial number: 4695a009
Valid from: Thu Jul 12 11:29:13 GMT+08:00 2007 until: Wed Oct 10 11:29:13 GMT+08:00 2007
Certificate fingerprints:
MD5: 88:AF:00:DA:4E:45:5E:60:F8:DB:5E:62:4E:E3:65:57
SHA1: 0F:FD:D8:0D:AD:E2:5B:DA:4E:A2:89:F0:4C:1B:B1:63:9D:1F:7F:89
Trust this certificate? [no]: yes
Certificate was added to keystore
D:/j2sdk1.4.2_11/bin>keytool.exe -list -keystore my.keystore
Enter keystore password: yechao
Keystore type: jks
Keystore provider: SUN
Your keystore contains 2 entries
my2ndcert, Jul 12, 2007, trustedCertEntry,
Certificate fingerprint (MD5): 88:AF:00:DA:4E:45:5E:60:F8:DB:5E:62:4E:E3:65:57
my1stcert, Jul 12, 2007, keyEntry,
Certificate fingerprint (MD5): F8:8E:3E:41:59:8A:34:F5:DF:0F:4B:DE:37:EB:87:1F