RSA私钥和公钥文件格式 (pkcs#7, pkcs#8, pkcs#12, pem)

Format Name Description
PKCS #7 Cryptographic Message Syntax Standard A PKCS #7 file can be used to store certificates, which is a SignedData structure without data (just the certificates). The file name extension is usually .p7b.p7c
PKCS #8 Private-Key Information Syntax Standard. Used to carry private certificate keypairs (encrypted or unencrypted).
PKCS #12 Personal Information Exchange Syntax Standard. Defines a file format commonly used to store private keys with accompanying public key certificates, protected with a password-based symmetric key. It is the successor to PFX from Microsoft.
DER Distinguished Encoding Rules A binary format for keys or certificates. It is a message transfer syntax specified by the ITU in X.690.
PEM Privacy Enhanced Mail Base64 encoded DER certificates or keys, with additional header and footer lines. 

The PEM private key format uses the header and footer lines: 
-----BEGIN RSA PRIVATE KEY----- 
-----END RSA PRIVATE KEY----- 

The PEM public key format uses the header and footer lines: 
-----BEGIN PUBLIC KEY----- 
-----END PUBLIC KEY----- 

The PEM certificate uses the header and footer lines: 
-----BEGIN CERTIFICATE----- 
-----END CERTIFICATE----- 

RSA Public Key file (PKCS#1)

The RSA Public key PEM file is specific for RSA keys.

It starts and ends with the tags:

-----BEGIN RSA PUBLIC KEY-----
BASE64 ENCODED DATA
-----END RSA PUBLIC KEY-----

Within the base64 encoded data the following DER structure is present:

RSAPublicKey ::= SEQUENCE {
    modulus           INTEGER,  -- n
    publicExponent    INTEGER   -- e
}

Public Key file (PKCS#8)

Because RSA is not used exclusively inside X509 and SSL/TLS, a more generic key format is available in the form of PKCS#8, that identifies the type of public key and contains the relevant data.

It starts and ends with the tags:

-----BEGIN PUBLIC KEY-----
BASE64 ENCODED DATA
-----END PUBLIC KEY-----

Within the base64 encoded data the following DER structure is present:

PublicKeyInfo ::= SEQUENCE {
  algorithm       AlgorithmIdentifier,
  PublicKey       BIT STRING
}

AlgorithmIdentifier ::= SEQUENCE {
  algorithm       OBJECT IDENTIFIER,
  parameters      ANY DEFINED BY algorithm OPTIONAL
}

So for an RSA public key, the OID is 1.2.840.113549.1.1.1 and there is a RSAPublicKey as the PublicKey key data bitstring.

RSA Private Key file (PKCS#1)

The RSA private key PEM file is specific for RSA keys.

It starts and ends with the tags:

-----BEGIN RSA PRIVATE KEY-----
BASE64 ENCODED DATA
-----END RSA PRIVATE KEY-----

Within the base64 encoded data the following DER structure is present:

RSAPrivateKey ::= SEQUENCE {
  version           Version,
  modulus           INTEGER,  -- n
  publicExponent    INTEGER,  -- e
  privateExponent   INTEGER,  -- d
  prime1            INTEGER,  -- p
  prime2            INTEGER,  -- q
  exponent1         INTEGER,  -- d mod (p-1)
  exponent2         INTEGER,  -- d mod (q-1)
  coefficient       INTEGER,  -- (inverse of q) mod p
  otherPrimeInfos   OtherPrimeInfos OPTIONAL
}

Private Key file (PKCS#8)

Because RSA is not used exclusively inside X509 and SSL/TLS, a more generic key format is available in the form of PKCS#8, that identifies the type of private key and contains the relevant data.

The unencrypted PKCS#8 encoded data starts and ends with the tags:

-----BEGIN PRIVATE KEY-----
BASE64 ENCODED DATA
-----END PRIVATE KEY-----

Within the base64 encoded data the following DER structure is present:

PrivateKeyInfo ::= SEQUENCE {
  version         Version,
  algorithm       AlgorithmIdentifier,
  PrivateKey      BIT STRING
}

AlgorithmIdentifier ::= SEQUENCE {
  algorithm       OBJECT IDENTIFIER,
  parameters      ANY DEFINED BY algorithm OPTIONAL
}

So for an RSA private key, the OID is 1.2.840.113549.1.1.1 and there is a RSAPrivateKey as the PrivateKey key data bitstring.

The encrypted PKCS#8 encoded data start and ends with the tags:

-----BEGIN ENCRYPTED PRIVATE KEY-----
BASE64 ENCODED DATA
-----END ENCRYPTED PRIVATE KEY-----

Within the base64 encoded data the following DER structure is present:

EncryptedPrivateKeyInfo ::= SEQUENCE {
  encryptionAlgorithm  EncryptionAlgorithmIdentifier,
  encryptedData        EncryptedData
}

EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier

EncryptedData ::= OCTET STRING

The EncryptedData OCTET STRING is a PKCS#8 PrivateKeyInfo (see above).

        

         

时间: 2024-08-02 10:45:11

RSA私钥和公钥文件格式 (pkcs#7, pkcs#8, pkcs#12, pem)的相关文章

c# rsa 私钥机密公钥解密

问题描述 使用pemPKCS#8格式私钥和公钥,在c#里测试使用公钥加密私钥解密没问题,使用私钥加密公钥解密报错不正确的项,难道c#私钥加密的公钥解密有问题,还是说我私钥加密的有问题? 解决方案 解决方案二:解密的时候报该项不存在解决方案三:.netRSA不支持这个功能,私钥只能解密不能加密.可以试试:解决方案四:如果你需要自己研发研发一个"证书授权"系统,需要私钥加密公钥解密,只能自己写一个RSA处理功能.解决方案五:.net的RSACryptoServiceProvider不支持使

基于私钥加密公钥解密的RSA算法C#实现

RSA算法是第一个能同时用于加密和数字签名的算法,也易于理解和操作. RSA是被研究得最广泛的公钥算法,从提出到现在已近二十年,经历了各种攻击的 考验,逐渐为人们接受,普遍认为是目前最优秀的公钥方案之一.RSA的安全性依 赖于大数的因子分解,但并没有从理论上证明破译RSA的难度与大数分解难度等价 . RSA的安全性依赖于大数分解.公钥和私钥都是两个大素数( 大于 100 个十进制位)的函数.据猜测,从一个密钥和密文推断出明文的难度等同于分解 两个大素数的积. 密钥对的产生.选择两个大素数,p 和

使用OpenSSL为支付宝生成RSA私钥

通过openssl工具生成RSA的公钥和私钥(opnssl工具可在互联网中下载到,也可以点此下载无线接口包,里面包含此工具)打开openssl文件夹下的bin文件夹,执行openssl.exe文件: 1)生成RSA私钥 输入"生成命令.txt"文件中:"genrsa -out rsa_private_key.pem 1024",并回车得到生成成功的结果,如下图: 此时,我们可以在bin文件夹中看到一个文件名为rsa_private_key.pem的文件,用记事本方式

Android版本支付宝集成获取私钥与公钥

项目需要,需要在客户端集成支付宝接口.就研究了一下:因为使用支付宝接口,就需要到支付宝官网:注册帐号,并申请.下面讲的是申请好之后的操作.登录成功之后,   店家我的商家服务-在页面的下方找到-->签约管理->找打 移动支付-–>点击下载集成文档->跳到新的页面,在页面下方->找到下载开发包,下载移动支付即可.然后解压出来之后一般会得到三个文件夹. 这个时候要打开文件名为:  支付宝钱包支付接口开发包2.0标准版的文件.打开之后有一个Demo 文件.打开Demo文件.里面会有

rsa-ios RSA 模和公钥指数

问题描述 ios RSA 模和公钥指数 最近在做一个ios客户端的项目,其中发送给服务端的数据请求要求使用RSA加密,模和公钥指数已经从服务端请求得到,弄了两三天一直没有解决,请问各位大神有没有好的解决思路,还请不吝赐教 解决方案 http://johnny.logdown.com/posts/69881-rsa-encryption-method-on-ios 解决方案二: 加密解密:http://witcheryne.iteye.com/blog/2171850 签名验签:http://bl

支付宝接口错误:您使用的私钥格式错误,请检查RSA私钥配置,charset = utf-8

调试支付宝条码支付的时候碰到个错误:您使用的私钥格式错误,请检查RSA私钥配置,charset = utf-8, 原因是我代码里的那私钥是直接复制pem文件里的代码的,可支付宝底层的sdk中默认是以文件的方式来进行, 引用 查看一下DefaultAopClient.cs,里面有一个自定义属性keyFromFile改成=false,则是用代码的方式进行,true的话则必须得传入pem的物理路径,如:HttpRuntime.AppDomainAppPath.ToString() + "App_Dat

RSA公钥加密—私钥解密&私钥加密—公钥解密&私钥签名—公钥验证签名

关于RSA算法,前面有介绍,点击打开链接. 这里直接有实现. 代码太多就不直接贴了,免积分下载. http://download.csdn.net/detail/acmjk/7310847

比特币私钥、公钥、钱包地址之间的关系

比特币交易涉及到很多密码学知识:公钥.私钥.哈希.对称加密.非对称加密.签名等等.那么哪些是需要用户认真保管不能对外泄露的,那些是需要用户公开的呢?先从钱包地址的生成说起. 1. 首先使用随机数发生器生成一个『私钥』.一般来说这是一个256bits的数,拥有了这串数字就可以对相应『钱包地址』中的比特币进行操作,所以必须被安全地保存起来. 2. 『私钥』经过SECP256K1算法处理生成了『公钥』.SECP256K1是一种椭圆曲线算法,通过一个已知『私钥』时可以算得『公钥』,而『公钥』已知时却无法

C#生成的RSA私钥,IOS怎么转格式呢?谁有过和苹果开发人员对接的经验。。。

问题描述 我生成了一对密钥,IOS(用的OC)上面保存私钥,C#生成的私钥比如为<RSAKeyValue><Modulus>0QN3kepHBGCVD11WFmlSTTZVCzkeGc9NB2p5tkZys4SV9/rBaxsrMkCeL88k+LJ4JIZGXna5+pchkDycAfiKOjp+B7fNT07Kwx6imIUfbRJrO1+Rq1s0NSPZnaiS8Q9Nb3YZwf498CDlxdx2A3z/WDbaJ/zG/jPHfl1l5SINw0s=</Modu