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;
}
PEM文件格式具体解析的更多相关文章
- PEM文件格式详细解析
PEM文件格式存档 Author:Roson sun sunxiao@tomonline-inc.com Time:2006-4-11 1. 描述: Openssl使用PEM(RFC 1421-14 ...
- MP4文件格式的解析
MP4文件格式的解析,以及MP4文件的分割算法 mp4应该算是一种比较复杂的媒体格式了,起源于QuickTime.以前研究的时候就花了一番的功夫,尤其是如何把它完美的融入到视频点播应用中,更是费尽了心 ...
- OPENSSL中RSA私钥文件(PEM格式)解析【一】
http://blog.sina.com.cn/s/blog_4fcd1ea30100yh4s.html 在PKCS#1 RSA算法标准中定义RSA私钥语法为: RSAPrivateKey ::= S ...
- EPUB文件格式简单解析
最近热衷于看轻小说,奈何某些网站样式排版属实糟糕,移动端体验极度不友好,实在无法忍受,于是希望能将网站内容爬取下来制作成EPUB格式的电子书. 抛开爬取网站内容不谈,通过解析EPUB文件后,大致掌握了 ...
- bmp文件格式详细解析
先区分几个概念:16色和16位色一样吗? 不一样! 颜色位数,即是用多少位字节表示的值,每一位可以表示0和1两值.通常图片的颜色深度,简称色深,就是用位数来表示的,所以,我通常会看到8位色,16位色, ...
- FAT32文件格式示例解析
1.前言 本文主要以一个示例来分析FAT32文件系统的格式,对FAT32文件系统的各个区域详细分析. 2.FAT32文件系统典型分区 3.FAT32文件系统示例 按如下步骤在ubuntu下创建FAT3 ...
- 《Unity系列》Json文件格式的解析——初级教程
Json作为轻量级的数据交换格式,被广泛应用于网络数据传输中.相关的解析工具层出不穷,一般掌握一个工具的应用其他的相应工具就能立马学会. 这里以C#中的LitJson为例给大家示范一下解析工具的用法. ...
- MP4文件格式的解析,以及MP4文件的分割算法
http://www.cnblogs.com/haibindev/archive/2011/10/17/2214518.html http://blog.csdn.net/pirateleo/arti ...
- [转载]X509证书中RSA公钥的提取与载入 pem key
原地址:https://blog.csdn.net/anddy926/article/details/8940377 由于项目需要,我计划利用openssl开发一个基本的CA,实现证书的发放等功能.在 ...
随机推荐
- stackoverflow,stackexchange,zhihu,ilewen,segmentfault,answerhub,question2answer,,
http://stackexchange.com/ http://question2answer.org/ http://answerhub.com/qa/ http://segmentfault.c ...
- Uva 11694 Gokigen Naname
基本思路是Dfs: 1. 一个一个格子摆放,以每个各自的左上角的点为基准点代表格子,比如(0,0)代表(0,0)(0,1)(1,0)(1,1)组成的格子,(0,1)代表(0,1)(0,2)(1,1), ...
- C# 调用迅雷 7 迅雷下载开放引擎
最近有个项目需要用winform调用迅雷下载.上网百度后发现迅雷自带的com组件从迅雷5之后就废掉了,除了能添加任务,其余功能全不能用.后来又发现了迅雷下载开放引擎这么个东西 http://thund ...
- APUE学习笔记——10.15 sigsetjmp和siglongjmp
转载自:sigsetjmp使用方法 如侵犯您的权益,请联系:windeal12@qq.com sigsetjmp使用方法 分类: c/c++ linux2012-02-03 12:33 1252人阅读 ...
- String详解说明
大家平时都string都不是很在意,但是每当面试碰到String的时候在“==”和equals之间就乱了,下面我来说一说String,也许不够全面,请大家多多指教,希望会帮到处于蒙圈状态的人们. 一. ...
- ThinkPHP - 登录流程
数据库: /* Navicat MySQL Data Transfer Source Server : 本地连接 Source Server Version : 50710 Source Host : ...
- Currency System in Geraldion (Codeforces 560A)
A Currency System in Geraldion Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64 ...
- PigCms 回复消息 "域名授权错误! 您使用的微信平台或源码为盗版"
本文地址:http://duwei.cnblogs.com/ Pigcms 将自动回复的API 写死了, 这里提供一个可用的API 在 PigCms/Lib/Action/Home/Weixinact ...
- python3.4.3将汉字转换为大写拼音首字母
from pypinyin import pinyin a=pinyin(u'杨强',type=FIRST_LETTER) --->此时返回一个列表并赋给a(元素也是列表) b=[] - ...
- struts2上传图片
在WEB-INF下新建一个content目录,建立一个upload.jsp <%@ page contentType="text/html; charset=UTF-8" l ...