PEM文件格式详细解析 收藏
PEM文件格式存档
Author:Roson sun sunxiao@tomonline-inc.com
Time:2006-4-11
1. 描述:
Openssl使用PEM(RFC 1421-1424)文档格式,如果使用其他语言包,则需要将此格式进行解码并将各个私公钥加入。
2. 说明:
a) 首先使用BASE64解码,如果是非ANSI TXT格式,需要做转换。
b) 一个RSA私钥包含一下信息(1024位):
>openssl rsa -in key.pem -noout -text
modulus:
00:d5:00:b2:18:c3:04:d1:ac:80:c6:22:a0:cc:5c:
f1:c0:4a:83:95:e5:c9:88:ae:31:64:ab:e1:15:42:
de:1a:da:bc:f5:d2:05:05:74:9d:d3:86:94:9b:9d:
74:bb:e5:72:a4:b8:40:27:61:88:d4:ac:20:b0:2b:
1c:1e:d7:9b:43:c5:06:b6:3a:b4:42:f0:5a:22:38:
23:74:99:4a:50:f1:f1:54:11:5a:44:0b:40:cf:83:
8a:73:6c:34:15:98:0a:7d:cf:0e:e5:00:8d:07:40:
f7:7d:fb:3f:64:35:1b:5d:a3:40:a9:51:fa:92:7d:
34:ef:03:fe:e0:59:56:31:25
数量:128
publicExponent:
01:00:01
数量:3
privateExponent:
11:e2:a8:11:ba:36:6a:60:c0:c3:62:5e:fc:2a:05:
c6:ae:bb:13:d8:22:af:0e:69:69:59:a1:61:c6:a6:
9d:bc:a6:47:41:e6:58:09:ed:c2:b8:37:3c:45:e1:
6a:71:9e:c9:c4:0a:e7:03:a2:98:b1:07:61:a3:8d:
0d:ed:ee:c4:7f:ca:fe:7d:c1:2e:2f:ca:3d:16:81:
4f:bf:ad:6a:03:ca:d7:80:dc:57:03:fe:cf:1f:37:
05:8d:58:79:14:01:1f:66:42:e4:f1:b6:9d:f1:01:
37:12:f4:d8:15:c0:cc:9b:fc:ea:55:cb:2f:ba:46:
fd:17:11:7e:43:b5:d1:15
数量:128
prime1:
00:ed:a0:e8:25:cc:1c:aa:f5:44:e2:78:9e:54:2c:
1d:60:cb:8f:32:b3:68:6d:b3:1d:cd:a9:8c:2a:ca:
02:bc:7b:a7:8b:06:1d:fa:af:4f:8c:26:81:54:12:
ec:7d:92:20:77:85:ef:6e:06:a6:8b:9c:eb:ab:6a:
e6:a1:83:6d:a3
数量:64(去掉开头的0)
prime2:
00:e5:78:66:5a:84:22:51:78:2d:14:fc:5f:f8:4e:
45:5f:e3:b2:5e:5b:50:a4:f5:55:e0:f3:0e:98:2c:
52:61:c2:50:df:f4:b7:bc:6e:69:3e:99:ff:1c:50:
a8:89:05:7a:2b:25:91:56:a5:a6:8f:8a:ec:80:82:
fa:eb:09:c2:97
数量:64(去掉开头的0)
exponent1:
00:89:e6:26:d2:48:71:1a:84:db:44:d1:da:8f:de:
49:ee:32:33:17:a9:25:a1:03:a0:f8:08:bc:5e:d8:
7c:5e:05:24:65:79:57:4c:73:10:26:b4:f1:b8:68:
82:f5:1c:27:db:34:ce:8d:7b:2e:8b:36:b5:4c:f4:
ec:82:2e:53:21
数量:64(去掉开头的0)
exponent2:
6a:16:a6:e3:74:31:55:8f:04:f0:ad:d9:44:b8:13:
14:c8:f5:5e:f0:42:b1:71:07:5a:2f:a4:f0:af:95:
0a:c3:46:96:b3:d1:fa:58:e5:69:5e:d2:f5:e9:48:
71:c8:c9:79:87:2d:d1:6c:56:3c:08:d3:5c:7a:b1:
bc:d6:4f:53
数量:64
coefficient:
62:dd:3f:f4:c7:30:c7:77:5e:8c:ae:c8:11:c1:23:
b0:6d:7d:07:54:8f:e7:12:1d:e1:00:ad:70:55:12:
43:f6:6f:a9:d7:94:9d:33:15:66:16:2d:d1:76:13:
33:0d:ae:6f:e3:3f:46:4b:4a:78:14:02:2e:72:66:
59:0c:2d:6a
数量:64
c) 与C#中RSAParameter结构体对应表:
说明
PEM
RSAParameter
Modulus
modulus
Exponent
Exponent
prime1
P
exponent1
Q
prime2
DP
exponent2
DQ
coefficient
InverseQ
privateExponent
D
d) PEM偏移(1024位,以0为开始字符,十进制)
说明
PEM私钥
PEM公钥
长度
Modulus
11
29
128
PublicExponent
141
159
3
PrivateExponent
147
×
128
Prime1
278
×
64
Prime2
345
×
64
Exponent1
412
×
64
Exponent2
478
×
64
Coefficient
545
×
64
e) 例子程序(C#):
/// <summary>
/// 用得到的解码值来得到相应的Parameter(BASE64->RSAParameter)
/// </summary>
/// <param name="hashKey">源</param>
/// <param name="type">0私钥1公钥</param>
/// <returns></returns>
public RSAParameters getKeyPara(string hashKey,int type)
{
RSAParameters rsaP=new RSAParameters();
byte[] tmpKeyNoB64=Convert.FromBase64String(hashKey);
int pemModulus=128;
int pemPublicExponent=3;
int pemPrivateExponent=128;
int pemPrime1=64;
int pemPrime2=64;
int pemExponent1=64;
int pemExponent2=64;
int pemCoefficient=64;
byte[] arrPemModulus=new byte[128];
byte[] arrPemPublicExponent=new byte[3];
byte[] arrPemPrivateExponent=new byte[128];
byte[] arrPemPrime1=new byte[64];
byte[] arrPemPrime2=new byte[64];
byte[] arrPemExponent1=new byte[64];
byte[] arrPemExponent2=new byte[64];
byte[] arrPemCoefficient=new byte[64];
if(type==0)//私钥
{
//Modulus
for(int i=0;i<pemModulus;i++)
{
arrPemModulus[i]=tmpKeyNoB64[11+i];
}
rsaP.Modulus=arrPemModulus;
//PublicExponent
for(int i=0;i<pemPublicExponent;i++)
{
arrPemPublicExponent[i]=tmpKeyNoB64[141+i];
}
rsaP.Exponent=arrPemPublicExponent;
//PrivateExponent
for(int i=0;i<pemPrivateExponent;i++)
{
arrPemPrivateExponent[i]=tmpKeyNoB64[147+i];
}
rsaP.D=arrPemPrivateExponent;
//Prime1
for(int i=0;i<pemPrime1;i++)
{
arrPemPrime1[i]=tmpKeyNoB64[278+i];
}
rsaP.P=arrPemPrime1;
//Prime2
for(int i=0;i<pemPrime2;i++)
{
arrPemPrime2[i]=tmpKeyNoB64[345+i];
}
rsaP.Q=arrPemPrime2;
//Exponent1
for(int i=0;i<pemExponent1;i++)
{
arrPemExponent1[i]=tmpKeyNoB64[412+i];
}
rsaP.DP=arrPemExponent1;
//Exponent2
for(int i=0;i<pemExponent2;i++)
{
arrPemExponent2[i]=tmpKeyNoB64[478+i];
}
rsaP.DQ=arrPemExponent2;
//Coefficient
for(int i=0;i<pemCoefficient;i++)
{
arrPemCoefficient[i]=tmpKeyNoB64[545+i];
}
rsaP.InverseQ=arrPemCoefficient;
}
else//公钥
{
for(int i=0;i<pemModulus;i++)
{
arrPemModulus[i]=tmpKeyNoB64[29+i];
}
rsaP.Modulus=arrPemModulus;
for(int i=0;i<pemPublicExponent;i++)
{
arrPemPublicExponent[i]=tmpKeyNoB64[159+i];
}
rsaP.Exponent=arrPemPublicExponent;
}
return rsaP;
}
分享到:
相关推荐
C#使用pem格式的密钥对文件来做RSA加解密接签名和验证签名,这里的pem文件是openssl命令生成的密钥对文件,其中私钥pem文件需要用openssl命令转换成pkcs8格式的pem文件。如果已有pem文件,也可以通过openssl命令转换...
通常C#使用xml格式的密钥文件,不能使用Linux下的公钥和私钥pem文件。而XML格式密钥对文件有移植性问题,在一个电脑上能用的xml密钥对,换一个电脑不一定能使用(需要从pem文件重新转换为xml)。本源码直接使用linux...
openssl 1.1.1C 中把pem格式的rsa密钥解析出,RSA格式的密钥,然后从RSA密钥中解析出RSA密钥中的,n,d,e,dp,dq等信息;
如题,这是一个自己产生的,可以验证双向或者单向验证的pem格式的证书,亲测有用 如题,这是一个自己产生的,可以验证双向或者单向验证的pem格式的证书,亲测有用
cacert.pem文件
PHP App Store Server API 苹果API退款 查询订单 历史订单 PHP校验签名解码需要用到的公钥文件 cer格式 pem格式
微信支付商户证书cert.zip中的rootca.pem文件。根据微信支付官方的信息:“由于绝大部分操作系统已内置了微信支付服务器证书的根CA证书, 2018年3月6日后, 不再提供CA证书文件(rootca.pem)下载。”
使用OpenSSL工具生成的RSA测试秘钥 PEM+对应的Hex 格式,经过测试有效。
支持PEM格式的RSA处理方案,直接提供源码,结构清晰明了
私钥为OpenSSL生成的PEM文件,本资源用C#从文件中读取私钥并加密,可以使用。
最新的生成ios推送pem文件的步骤 如果有需求的可以下载看看,只要按照步骤写一定没有问题。
用OpenSSL 生成了公钥和私钥文件,格式为PEM的,现在用C#想要从文件中读取公钥和私钥。 生成公钥和私钥方式如下: DSA公私钥可以使用OpenSSL 生成,如下: a) 生成DSA参数 openssl dsaparam -out dsa_param.pem ...
生成系统签名所需的文件,当然这是官方的,如果系统是定制的话这2个文件就不适用了,需要自己找系统提供商来要这2个文件。使用方法: 将三个文件文件放在同一个目录下,执行如下命令,会生成platform.keystore文件: ...
pem:轻松解析PEM文件 pem是许可的Python模块,用于解析和拆分,即Base64编码的DER密钥和证书。 它在Python 2.7和3.5+上运行,没有依赖关系,并且不会尝试以任何方式解释证书数据。 它源于从各种证书部署中加载...
在 linux 系统客户端若要登录 目标虚拟机,使用 xxx.pem 密钥对文件登录,使用以下命令:在 windows 上登录 linux 可用其他虚拟终端软件
在wamp环境里,当你配置好了“extension=php_curl.dll”事项,还遇到“cURL error 60: SSL certificate: unable to get local issuer certificate.”时,就需要把该文件放到“E:\wamp\bin\php\php5.5.12\extras\ssl...
本资源是自建的一个CA证书和私钥,可以用于测试https网络安全测试,在服务器端使用此证书配置,终端访问可以实现https访问,其中证书和密钥都是以文件的形式存储,证书的有效期是两年。
如题呀,也没啥好说的嘛。主要是自己当时搜索PK8文件的时候,全是关于Android的东西,根本就是误导人,好伐,发个这个文档,给其他人一个方向吧!
1、pem文件概述 pem文件是服务器向苹果服务器做推送时候需要的文件,主要是给php向苹果服务器验证时使用,下面介绍一下pem文件的生成。 2、生成pem文件步骤 1、打开钥匙串,选择需要生成的推送证书 2、将...
.net使用 pem格式的RSA公钥,私钥 加解密 ,NET使用OpenSSL生成的pem密钥文件,