openssl/keytool error: java.lang.Exception: Input not an X.509 certificate

openssl/keytool error: java.lang.Exception: Input not an X.509 certificate

我已经通过 Openssl 创建了证书

Openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=nginxsvc/O=nginxsvc"

然后使用 OpenSSL 创建了一个 PKCS#12 文件:

openssl pkcs12 -export -in tls.crt -inkey tls.key -out tls.p12

然后使用

将其转换为 JKS
keytool -importkeystore -srckeystore tls.p12  -srcstoretype PKCS12  -destkeystore tls.jks  -deststoretype JKS

现在像这样通过 keytool 导入这个 jks 文件时

keytool -import -noprompt -trustcacerts -alias "nginxsvc" -file tls.jks -keystore "C:\Program Files\Java\jdk1.8.0_152\jre\lib\security\cacerts"

我得到

keytool error: java.lang.Exception: Input not an X.509 certificate

-import 需要证书文件,而不是 JKS。 尝试:

keytool -import -noprompt -trustcacerts -alias "nginxsvc" -file tls.crt -keystore "C:\Program Files\Java\jdk1.8.0_152\jre\lib\security\cacerts"