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

简介: FormatNameDescriptionPKCS #7Cryptographic Message Syntax StandardA PKCS #7 file can be used to store certificates, which is a SignedData structure without data (just the certificates).
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).

        

         

目录
相关文章
|
2天前
|
存储 算法 安全
PKCS#1、PKCS#5、PKCS#7、PKCS#8到底是什么?
PKCS#1、PKCS#5、PKCS#7、PKCS#8到底是什么?
327 0
如何生成pem密钥
本帖是介绍使用支付宝提供的一键生成密钥工具和OpenSSL工具生成pem格式密钥,仅供参考!! 可参看开放平台文档链接实现:[url]https://docs.open.alipay.com/291/106097[/url] 1.直接使用支付宝提供的一键生成工具生成; 2.使用OpenSSL工具生成。
4702 0
如何生成RSA,RSA2密钥
密钥生成或如何使用(创建应用):[url]https://openclub.alipay.com/read.php?tid=1606&fid=72[/url] 1.密钥生成工具下载:[url]https://docs.
1474 1
|
2天前
|
算法 Java 数据安全/隐私保护
RSA 加解密 1024 位 & 2048 位
RSA 加解密 1024 位 & 2048 位
72 0
|
5月前
|
存储 算法 安全
C++ CryptoPP使用RSA加解密
Crypto++ (CryptoPP) 是一个用于密码学和加密的 C++ 库。它是一个开源项目,提供了大量的密码学算法和功能,包括对称加密、非对称加密、哈希函数、消息认证码 (MAC)、数字签名等。Crypto++ 的目标是提供高性能和可靠的密码学工具,以满足软件开发中对安全性的需求。RSA(Rivest-Shamir-Adleman)是一种非对称加密算法,由三位密码学家Ron Rivest、Adi Shamir和Leonard Adleman于1977年共同提出。RSA算法被广泛应用于信息安全领域,特别是在数字签名和密钥交换等场景中。
121 0
C++ CryptoPP使用RSA加解密
|
算法 Linux 数据安全/隐私保护
RSA加密算法
RSA加密算法
168 0
RSA加密算法
|
存储 数据安全/隐私保护 Windows
密码学系列之:PEM和PKCS7,PKCS8,PKCS12
PEM是一种常见的保存key或者证书的格式,PEM格式的文件一般来说后缀是以.pem结尾的。那么PEM到底是什么呢?它和常用的证书格式PKCS7和PKCS12有什么关系呢?一起来看看吧。
RSA,RSA2密钥和MD5说明
说明:   现在关于RSA,RSA2,DSA,MD5,AES加密原理这里就不说了,网上已经有很完善的资料可以供我们了解。   下面说说在集成支付宝接口常用的RSA2(强烈推荐使用!!!),RSA,MD5(不推荐使用) 签名方式使用优先级   RSA2>RSA>MD5 支付宝接口签名支持表     注:老板wap支付密钥相关产品已经下架大家无需关注 常见问题:   1.
1887 0
如何生成RSA2密钥
密钥文件说明:    1、rsa_private_key.pem:原始私钥(又称pkcs1私钥),适用于非Java开发语言;  2、rsa_private_key_pkcs8.pem:pkcs8私钥,适用于Java开发语言;  3、rsa_public_key.pem:商户公钥,需上传至应用中加签方式的应用公钥位置。
1949 0
|
网络安全 Windows