如何用私钥将.pfx文件转换为密钥库? [英] How to convert .pfx file to keystore with private key?

查看:213
本文介绍了如何用私钥将.pfx文件转换为密钥库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要签署Android应用程式( .apk )。

我有 .pfx 文件。我通过Internet Explorer将其转换为 .cer 文件,然后将 .cer 转换为 .keystore 使用keytool。然后我试图用jarsigner签署 .apk ,但它说.keystore不包含私钥。

I need to sign Android application (.apk).
I have .pfx file. I converted it to .cer file via Internet Explorer and then converted .cer to .keystore using keytool. Then I've tried to sign .apk with jarsigner but it says that .keystore doesn't content a private key.

我做错了什么?

推荐答案

使用JDK 1.6或更高版本

Using JDK 1.6 or later

Justin在下面的注释中指出,keytool单独使用下面的命令是可以做到这一点(虽然只在JDK 1.6和更高版本中):

It has been pointed out by Justin in the comments below that keytool alone is capable of doing this using the following command (although only in JDK 1.6 and later):

keytool -importkeystore -srckeystore mypfxfile.pfx -srcstoretype pkcs12 
-destkeystore clientcert.jks -deststoretype JKS

使用JDK 1.5或更低版本

OpenSSL做所有。 JGuru上的这个答案是我到目前为止找到的最好的方法。

OpenSSL can do it all. This answer on JGuru is the best method that I've found so far.

首先,请确保您已安装 OpenSSL 。许多操作系统已经安装了我在Mac OS X上找到的。

Firstly make sure that you have OpenSSL installed. Many operating systems already have it installed as I found with Mac OS X.

以下两个命令将pfx文件转换为可以作为Java PKCS12密钥打开的格式store:

The following two commands convert the pfx file to a format that can be opened as a Java PKCS12 key store:

openssl pkcs12 -in mypfxfile.pfx -out mypemfile.pem
openssl pkcs12 -export -in mypemfile.pem -out mykeystore.p12 -name "MyCert"

注意,第二个命令中提供的名称是

NOTE that the name provided in the second command is the alias of your key in the new key store.

您可以使用Java keytool实用程序使用以下命令验证密钥存储区的内容:

You can verify the contents of the key store using the Java keytool utility with the following command:

keytool -v -list -keystore mykeystore.p12 -storetype pkcs12

最后,如果需要,您可以通过将上面创建的密钥存储导入新的密钥库,将其转换为JKS密钥存储:

Finally if you need to you can convert this to a JKS key store by importing the key store created above into a new key store:

keytool -importkeystore -srckeystore mykeystore.p12 -destkeystore clientcert.jks -srcstoretype pkcs12 -deststoretype JKS

这篇关于如何用私钥将.pfx文件转换为密钥库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆