1. Generate the KeyStore file
Execute the following command at the command line:
Shell Code Collection Code
keytool -genkey -validity 36000 -alias www.zlex.org -keyalg RSA -keystore d:\zlex.keystore
which
-genkey indicates that the key is generated
-validity Specify the certificate validity period, here is 36,000 days
-ALIAS Specifies the alias, this is www.zlex.org
-KEYALG Specifies the algorithm, here is the RSA
-keystore Specify the storage location, this is D:\zlex.keystore
The password I used here is 123456.
Console output:
Console Code Collection code
输入keystore密码: 再次输入新密码: 您的名字与姓氏是什么? [Unknown]: www.zlex.org 您的组织单位名称是什么? [Unknown]: zlex 您的组织名称是什么? [Unknown]: zlex 您所在的城市或区域名称是什么? [Unknown]: BJ 您所在的州或省份名称是什么? [Unknown]: BJ 该单位的两字母国家代码是什么 [Unknown]: CN CN=www.zlex.org, OU=zlex, O=zlex, L=BJ, ST=BJ, C=CN 正确吗? [否]: Y 输入<tomcat>的主密码 (如果和 keystore 密码相同,按回车): 再次输入新密码:
At this point, a Zlex.keystore file is generated under the D drive.
2. Generate a self-signed certificate
Light has KeyStore file is not enough, also need certificate file, certificate is directly provided to the outside public key credentials.
To export a certificate:
Shell Code Collection Code
keytool -export -keystore d:\zlex.keystore -alias www.zlex.org -file d:\zlex.cer -rfc
which
-export specified as an export operation
-keystore Specifying KeyStore files
-alias specifying an alias in the export KeyStore file
-file pointing to the export path
-RFC output in text format, i.e. output in BASE64 encoding
The code here is 123456.
Console output:
Console Code Collection code
输入keystore密码: 保存在文件中的认证 <d:\zlex.cer>
Java KeyStore using commands to generate KeyStore files