我使用以下命令创建我的密钥库:
keytool -genkey -keystore myStore.keystore -keyalg RSA -keysize 1024 -alias myAlias
Run Code Online (Sandbox Code Playgroud)
我怎么能生成一个过期的过期日期(使用它?我想用过期的证书测试我的应用程序的行为).
您可以使用以下参数使用keytool命令生成过期证书.
-开始日期
-validity
虽然有效性参数只需要输入天数,但是有效性开始时可以使用startdate参数.输入到startdate参数的格式[yyyy/mm/dd] [HH:MM:SS]
有关详细信息,请参阅此链接 http://docs.oracle.com/javase/7/docs/technotes/tools/windows/keytool.html
使用 java keytool,密钥库证书的最短有效期可以为 1 天。
编辑:看起来有一个选项-startdate@shyam0191 已经回答了。
因此,您不能(更正:您实际上可以)生成具有过去日期的证书。我建议使用以下命令,这将生成一个有效期为 1 天的证书,第二天您就可以使用它进行测试:
keytool -selfcert -alias Test -genkey -keystore myStore.keystore -keyalg RSA -validity 1
Run Code Online (Sandbox Code Playgroud)
或使用@shyam0191的答案,最终会有相同的最终结果(但更快)。
You can use below openssl commands to generate expired certificates, which mimics the official process to sign certificates.
Note: Only tested on Linux.
#Create CA key, which means you are now the CA using root.key and root.cer to sign certificates
openssl genrsa 4096 > root.key
#Create CA certificate expired ten years later
openssl req -new -x509 -key root.key -out root.cer -days 3650
Run Code Online (Sandbox Code Playgroud)
#Generates your own private key
openssl genrsa 4096 > server.key
#Build a Certificate Signing Request
openssl req -new -key server.key -out server.csr
Run Code Online (Sandbox Code Playgroud)
#sign the certificate and make the certificate expired 1 day ago. Pay attention to the negative -days argument( not working on MacOS )
openssl x509 -req -in server.csr -CA root.cer -CAkey root.key -CAcreateserial -out server.cer -days -1
Run Code Online (Sandbox Code Playgroud)
openssl x509 -noout -text -in server.cer
Run Code Online (Sandbox Code Playgroud)
Validity
Not Before: Mar 7 09:11:13 2019 GMT
Not After : Mar 6 09:11:13 2019 GMT
| 归档时间: |
|
| 查看次数: |
5558 次 |
| 最近记录: |