openssl的证书格式转换

openssl的证书格式转换

证书转换

PKCS 全称是 Public-Key Cryptography Standards ,是由 RSA 实验室与其它安全系统开发商为促进公钥密码的发展而制订的一系列标准,PKCS 目前共发布过 15 个标准。 常用的有:

PKCS#7 Cryptographic Message Syntax Standard

PKCS#10 Certification Request Standard

PKCS#12 Personal Information Exchange Syntax Standard

X.509是常见通用的证书格式。所有的证书都符合为Public Key Infrastructure (PKI) 制定的 ITU-T X509 国际标准。

PKCS#7 常用的后缀是: .P7B .P7C .SPC

PKCS#12 常用的后缀有: .P12 .PFX

X.509 DER 编码(ASCII)的后缀是: .DER .CER .CRT

X.509 PAM 编码(Base64)的后缀是: .PEM .CER .CRT

.cer/.crt是用于存放证书,它是2进制形式存放的,不含私钥。

.pem跟crt/cer的区别是它以Ascii来表示。

pfx/p12用于存放个人证书/私钥,他通常包含保护密码,2进制方式

p10是证书请求

p7r是CA对证书请求的回复,只用于导入

p7b以树状展示证书链(certificate chain),同时也支持单个证书,不含私钥。

1. CA证书

用openssl创建CA证书的RSA密钥(PEM格式):

openssl genrsa -des3 -out ca.key 1024

2. 创建CA证书有效期为一年

用openssl创建CA证书(PEM格式,假如有效期为一年):

openssl req -new -x509 -days 365 -key ca.key -out ca.crt -config openssl.cnf

openssl是可以生成DER格式的CA证书的,最好用IE将PEM格式的CA证书转换成DER格式的CA证书。

3. x509转换为pfx

openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt

4. PEM格式的ca.key转换为Microsoft可以识别的pvk格式

pvk -in ca.key -out ca.pvk -nocrypt -topvk

5. PKCS#12 到 PEM 的转换

openssl pkcs12 -nocerts -nodes -in cert.p12 -out private.pem  验证  openssl pkcs12 -clcerts -nokeys -in cert.p12 -out cert.pem

6. 从 PFX 格式文件中提取私钥格式文件 (.key)

openssl pkcs12 -in mycert.pfx -nocerts -nodes -out mycert.key

7. 转换 pem 到到 spc

openssl crl2pkcs7 -nocrl -certfile venus.pem  -outform DER -out venus.spc

用 -outform -inform 指定 DER 还是 PAM 格式。例如:

openssl x509 -in Cert.pem -inform PEM -out cert.der -outform DER

8. PEM 到 PKCS#12 的转换

openssl pkcs12 -export -in Cert.pem -out Cert.p12 -inkey key.pem

IIS 证书

cd c:\openssl            set OPENSSL_CONF=openssl.cnf            openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt

server.key和server.crt文件是Apache的证书文件,生成的server.pfx用于导入IIS

9. How to Convert PFX Certificate to PEM Format for SOAP

$ openssl pkcs12 -in test.pfx -out client.pem  Enter Import Password:  MAC verified OK  Enter PEM pass phrase:  Verifying - Enter PEM pass phrase:

IOS开发 把cer证书转为p12证书

在 Mac OS 上将 iPhone 开发人员证书转换为 P12 文件

从 Apple 下载 Apple iPhone 证书后,将其导出为 P12 证书格式。在 Mac? OS 上执行以下操作:

打开钥匙串访问应用程序(位于应用程序/实用工具文件夹中)。

如果尚未将该证书添加到钥匙串,请选择“文件”>“导入”。然后浏览到您从 Apple 获取的证书文件(.cer 文件)。

在钥匙串访问中选择密钥类别。

选择与 iPhone 开发证书相关联的私钥。

该私钥由 iPhone 开发人员识别:与之配对的<名字><姓氏>公共证书。

选择“文件”>“导出项目”。

以个人信息交换 (.p12) 文件格式保存您的密钥。

系统将提示您创建一个尝试在其他计算机上导入此密钥时需要使用的密码。

在 Windows 上将 Apple 开发人员证书转换为 P12 文件

要使用 Flash CS5 开发 iPhone 应用程序,则必须使用 P12 证书文件。基于从 Apple 收到的 Apple iPhone 开发人员证书文件生成此证书。

将从 Apple 收到的开发人员证书文件转换成 PEM 证书文件。从 OpenSSL bin 目录运行以下命令行语句:

openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM

如果您使用的是 Mac 计算机上钥匙串中的私钥,则将其转换成 PEM 密钥:

openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem

现在,您可以基于密钥和 PEM 版本的 iPhone 开发人员证书生成有效的 P12 文件:

openssl pkcs12 -export -inkey mykey.key -in developer_identity.pem -out iphone_dev.p12

如果您使用的是 Mac OS 钥匙串中的密钥,则使用上一步骤中生成的 PEM 版本。否则,请使用以前生成的 OpenSSL 密钥(位于 Windows 上)。

按步骤来,拿到cer文件后发觉无法导出p12,有过来人指点下啊

我先到开发者授权系统,进入Certificates页面后,点击Distribution标签。如下图,下载一个

AppleWWDRCA(Apple World Wide Developer Relations Certification Authority)证书文件到本地,

2:然后到开发者授权系统证书页面,点击Request Certificate,按照我们之前介绍过的流程上传一个

CSR文件,然后下载一个cer文件,

打开cer文件之后,在钥匙串里面没有发现相应的钥匙。

也无导出p12的提示

这是怎么回事?谁解决过啊?

双击cer文件,钥匙串里面没相应的钥匙??在certificates分栏里面哦,注意找找看。找到key单击右键就又导出p12文件选项

http://blog.csdn.net/wave_1102/article/details/7669152

里面有介绍

谢谢 解决了  我把里面我在我的证书里面,把所有证书都删除了,然后新建证书请求,然后再申请cer回来安装后就能导出P12了,不过还是没明白什么原因,可能跟以前生成的证书有冲突还是怎么滴

将开发人员证书转换为 P12 文件

要使用 Flash Professional CS5 开发 iPhone 应用程序,您必须使用 P12 证书文件。基于从 Apple 收到的 Apple iPhone 开发人员证书文件生成此证书。

在 Mac OS 上将 iPhone 开发人员证书转换为 P12 文件

从 Apple 下载 Apple iPhone 证书后,将其导出为 P12 证书格式。在 Mac® OS 上执行以下操作:

打开钥匙串访问应用程序(位于应用程序/实用工具文件夹中)。

如果尚未将该证书添加到钥匙串,请选择“文件”>“导入”。然后浏览到您从 Apple 获取的证书文件(.cer 文件)。

在钥匙串访问中选择密钥类别。

选择与 iPhone 开发证书相关联的私钥。

该私钥由 iPhone 开发人员识别:与之配对的<名字><姓氏>公共证书。

选择“文件”>“导出项目”。

以个人信息交换 (.p12) 文件格式保存您的密钥。

系统将提示您创建一个尝试在其他计算机上导入此密钥时需要使用的密码。

在 Windows 上将 Apple 开发人员证书转换为 P12 文件

要使用 Flash CS5 开发 iPhone 应用程序,则必须使用 P12 证书文件。基于从 Apple 收到的 Apple iPhone 开发人员证书文件生成此证书。

将从 Apple 收到的开发人员证书文件转换成 PEM 证书文件。从 OpenSSL bin 目录运行以下命令行语句:

openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM

如果您使用的是 Mac 计算机上钥匙串中的私钥,则将其转换成 PEM 密钥:

openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem

现在,您可以基于密钥和 PEM 版本的 iPhone 开发人员证书生成有效的 P12 文件:

openssl pkcs12 -export -inkey mykey.key -in developer_identity.pem -out iphone_dev.p12

如果您使用的是 Mac OS 钥匙串中的密钥,则使用上一步骤中生成的 PEM 版本。否则,请使用以前生成的 OpenSSL 密钥(位于 Windows 上)。

This section provides a tutorial example on how to convert a

private key file from the traditional format into PKCS#8 format using

the 'openssl pkcs8' command. Keys can still be encoded with DER or PEM

with or without DES encryption in PKCS#8 format.

Once I have my private key stored in the traditional format,

I can use the "openssl pkcs8" command to convert it into PKCS#8 format.

My plan was to try to do the following:

"openssl pkcs8 -topk8" to convert the key file format to PKCS#8 with PEM encoding, but no encryption.

"openssl pkcs8 -topk8" to convert the key file format to PKCS#8 with DER encoding, but no encryption.

"openssl pkcs8 -topk8" to convert the key file format to PKCS#8 with PEM encoding and encryption.

"openssl pkcs8 -topk8" to convert the key file format to PKCS#8 with DER encoding and encryption.

My command session was recorded as blow:

>rem PKCS#8 format, PEM encoding, no encryption

>openssl pkcs8 -topk8 -in openssl_key.pem -inform pem

-out openssl_key_pk8.pem -outform pem -nocrypt

>rem PKCS#8 format, DER encoding, no encryption

>openssl pkcs8 -topk8 -in openssl_key.pem -inform pem

-out openssl_key_pk8.der -outform der -nocrypt

>rem PKCS#8 format, PEM encoding, encrypted

>openssl pkcs8 -topk8 -in openssl_key.pem -inform pem

-out openssl_key_pk8_enc.pem -outform pem

Enter Encryption Password: keypass

Verifying - Enter Encryption Password: keypass

Loading 'screen' into random state - done

>rem PKCS#8 format, DER encoding, encrypted

>openssl pkcs8 -topk8 -in openssl_key.pem -inform pem

-out openssl_key_pk8_enc.der -outform der

Enter Encryption Password: keypass

Verifying - Enter Encryption Password: keypass

Loading 'screen' into random state - done

All commands executed as expected this time. I got my RSA private key stored in

OpenSSL traditional format and PKCS#8 format in 7 flavors:

04/01/2007  09:55 AM              608 openssl_key.der

04/01/2007  09:52 AM              887 openssl_key.pem

04/01/2007  10:01 AM              958 openssl_key_des.pem

04/01/2007  10:29 AM              634 openssl_key_pk8.der

04/01/2007  10:28 AM              916 openssl_key_pk8.pem

04/01/2007  11:53 AM              677 openssl_key_pk8_enc.der

04/01/2007  10:29 AM              993 openssl_key_pk8_enc.pem

Now the question is how to verify them? Looks like there no easy tool to do this.

I will leave this task later by writing a Java program to verify them.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,015评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,262评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,727评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,986评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,363评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,610评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,871评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,582评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,297评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,551评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,053评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,385评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,035评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,079评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,841评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,648评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,550评论 2 270

推荐阅读更多精彩内容