如何从 Java 密钥库创建 PFX 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/527610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I create a PFX file from a Java Keystore?
提问by Christian Berg
I have a Java keystore (.jks file) holding a single certificate. How can I create a .pfx file from this keystore?
我有一个持有单个证书的 Java 密钥库(.jks 文件)。如何从此密钥库创建 .pfx 文件?
回答by Nick Fortescue
This guy() seems to have written a little Java class and batch file with good instructions to do this here: http://www.crionics.com/products/opensource/faq/signFree.htm#DownloadTools
这家伙()似乎已经写了一个小的 Java 类和批处理文件,并在此处提供了很好的说明:http: //www.crionics.com/products/opensource/faq/signFree.htm#DownloadTools
If you want to do it yourself the key lines in the .bat file seem to be uses
如果你想自己做 .bat 文件中的关键行似乎是使用
keytool -export -rfc -keystore %KEYSTORE% -storepass %PASSWORD% -alias %ALIAS% > %CERT_64%
java -classpath %JAVACLASSPATH% ExportPrvKey %KEYSTORE% %PASSWORD% %ALIAS% > %PKEY_8%
openssl enc -in %PKEY_8% -a >> %PKEY_64%
openssl pkcs12 -inkey %PKEY_64% -in %CERT_64% -out %CERT_P12% -export
where ExportPrvKey does the step of extracting the private key from the keystore.
其中,ExportPrvKey 执行从密钥库中提取私钥的步骤。
回答by happy.cze
回答by Bruno
From Java 6 onwards, keytool
has an -importkeystore
option, which should be able to convert a JKS store into a PKCS#12 store (.p12/.pfx):
从 Java 6 开始,keytool
有一个-importkeystore
选项,它应该能够将 JKS 存储转换为 PKCS#12 存储(.p12/.pfx):
keytool -importkeystore -srckeystore thekeystore.jks \
-srcstoretype JKS \
-destkeystore thekeystore.pfx \
-deststoretype PKCS12
回答by Orion Edwards
You can export a PFX file including private key, with the following command:
您可以使用以下命令导出包含私钥的 PFX 文件:
keytool -importkeystore -deststorepass secret -destkeypass secret -destkeystore KEYSTOREFILE.jks -srckeystore PFXFILE.pfx -srcstoretype PKCS12 -srcstorepass secret