首页 > 代码库 > keytool创建Keystore和Trustsotre文件
keytool创建Keystore和Trustsotre文件
一、生成一个含有一个私钥的keystore文件
user@ae01:~$ keytool -genkey -keystore keystore -alias jetty-azkaban -keyalg RSAEnter keystore password: Re-enter new password: What is your first and last name? [Unknown]: azkabanWhat is the name of your organizational unit? [Unknown]: JettyWhat is the name of your organization? [Unknown]: AugWhat is the name of your City or Locality? [Unknown]: SHWhat is the name of your State or Province? [Unknown]: SHWhat is the two-letter country code for this unit? [Unknown]: 86Is CN=azkaban, OU=Jetty, O=Aug, L=SH, ST=SH, C=86 correct? [no]: yesEnter key password for <jetty-azkaban2>(RETURN if same as keystore password):
二、验证生成的keystore文件
keytool -list -v -keystore keystore.jks Enter keystore password:
Keystore type: JKSKeystore provider: SUNYour keystore contains 1 entryAlias name: jetty-azkabanCreation date: Jul 9, 2014Entry type: PrivateKeyEntryCertificate chain length: 1Certificate[1]:Owner: CN=azkaban, OU=Jetty, O=Aug, L=SH, ST=SH, C=86Issuer: CN=azkaban, OU=Jetty, O=Aug, L=SH, ST=SH, C=86Serial number: 5f84c457Valid from: Wed Jul 09 15:09:41 CST 2014 until: Tue Oct 07 15:09:41 CST 2014Certificate fingerprints: MD5: 2F:D3:D9:61:0E:DD:B5:CD:96:E0:5F:C0:C5:87:54:FD SHA1: FD:0B:B4:57:37:CE:7A:40:02:DF:43:2A:A0:2A:70:A5:AE:AE:45:51 SHA256: D5:EE:99:BF:E6:31:FC:4E:B3:B4:CD:8B:07:1D:D1:44:D0:CD:91:D8:83:15:F8:9D:D9:5E:41:E1:AA:FB:45:CB Signature algorithm name: SHA256withRSA Version: 3Extensions:#1: ObjectId: 2.5.29.14 Criticality=falseSubjectKeyIdentifier [KeyIdentifier [0000: B5 97 26 95 F0 F5 D4 9E 4C 28 84 28 D4 B0 21 90 ..&.....L(.(..!.0010: 6E A7 1E E0 n...]]**************************************************************************************
三、导出凭证文件
user@ae01:~$ keytool -export -alias jetty-azkaban -keystore keystore.jks -rfc -file selfs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W7ZekzvVXQhqADEpsmZ6Hd30dmzJWkI2lwbsQNE9vf3dG7qKLDeWi78A7KZc3qtBvDUmyheztUpmAM/PCoO+vmCgZALkaQ1sTWORqQOsylSBY2ZDul0si+rI0nZ9Y6dTxhgFxe9QoB-----END CERTIFICATE-----
四、导入认凭证件cer文件到truststore文件
user@ae01:~$ keytool -import -alias certificatekey -file selfsignedcert.cer -keystore truststore.jksEnter keystore password:
查看生成的truststore文件
user@ae01:~$ keytool -list -v -keystore truststore.jksEnter keystore password:Keystore type: JKSKeystore provider: SUNYour keystore contains 1 entryAlias name: jetty-azkabanCreation date: Jul 9, 2014Entry type: trustedCertEntryOwner: CN=azkaban, OU=Jetty, O=Aug, L=SH, ST=SH, C=86Issuer: CN=azkaban, OU=Jetty, O=Aug, L=SH, ST=SH, C=86Serial number: 5f84c457Valid from: Wed Jul 09 15:09:41 CST 2014 until: Tue Oct 07 15:09:41 CST 2014Certificate fingerprints: MD5: 2F:D3:D9:61:0E:DD:B5:CD:96:E0:5F:C0:C5:87:54:FD SHA1: FD:0B:B4:57:37:CE:7A:40:02:DF:43:2A:A0:2A:70:A5:AE:AE:45:51 SHA256: D5:EE:99:BF:E6:31:FC:4E:B3:B4:CD:8B:07:1D:D1:44:D0:CD:91:D8:83:15:F8:9D:D9:5E:41:E1:AA:FB:45:CB Signature algorithm name: SHA256withRSA Version: 3Extensions:#1: ObjectId: 2.5.29.14 Criticality=falseSubjectKeyIdentifier [KeyIdentifier [0000: B5 97 26 95 F0 F5 D4 9E 4C 28 84 28 D4 B0 21 90 ..&.....L(.(..!.0010: 6E A7 1E E0 n...]]**************************************************************************************
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。