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

摘要:
RSA私钥和公钥文件格式(pkcs#1,pkcs#8,pkcs#12,pem)2018年03月07日11:57:22阅读数:674FormatNameDescriptionPKCS#7CryptographicMessageSyntaxStandardAPKCS#7filecanbeusedtostorecertificates,whichisaSignedDatastructurewithout
RSA私钥和公钥文件格式 (pkcs#1, pkcs#8, pkcs#12, pem)
2018年03月07日 11:57:22
阅读数:674
FormatNameDescription
PKCS #7Cryptographic Message Syntax StandardA 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 #8Private-Key Information Syntax Standard.Used to carry private certificate keypairs (encrypted or unencrypted).
PKCS #12Personal 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.
DERDistinguished Encoding RulesA binary format for keys or certificates. It is a message transfer syntax specified by the ITU in X.690.
PEMPrivacy Enhanced MailBase64 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:

  1. -----BEGIN RSA PUBLIC KEY-----
  2. BASE64 ENCODED DATA
  3. -----END RSA PUBLIC KEY-----

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

  1. RSAPublicKey ::= SEQUENCE {
  2. modulus INTEGER, -- n
  3. publicExponent INTEGER -- e
  4. }

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:

  1. -----BEGIN PUBLIC KEY-----
  2. BASE64 ENCODED DATA
  3. -----END PUBLIC KEY-----

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

  1. PublicKeyInfo ::= SEQUENCE {
  2. algorithm AlgorithmIdentifier,
  3. PublicKey BIT STRING
  4. }
  5. AlgorithmIdentifier ::= SEQUENCE {
  6. algorithm OBJECT IDENTIFIER,
  7. parameters ANY DEFINED BY algorithm OPTIONAL
  8. }

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:

  1. -----BEGIN RSA PRIVATE KEY-----
  2. BASE64 ENCODED DATA
  3. -----END RSA PRIVATE KEY-----

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

  1. RSAPrivateKey ::= SEQUENCE {
  2. version Version,
  3. modulus INTEGER, -- n
  4. publicExponent INTEGER, -- e
  5. privateExponent INTEGER, -- d
  6. prime1 INTEGER, -- p
  7. prime2 INTEGER, -- q
  8. exponent1 INTEGER, -- d mod (p-1)
  9. exponent2 INTEGER, -- d mod (q-1)
  10. coefficient INTEGER, -- (inverse of q) mod p
  11. otherPrimeInfos OtherPrimeInfos OPTIONAL
  12. }

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:

  1. -----BEGIN PRIVATE KEY-----
  2. BASE64 ENCODED DATA
  3. -----END PRIVATE KEY-----

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

  1. PrivateKeyInfo ::= SEQUENCE {
  2. version Version,
  3. algorithm AlgorithmIdentifier,
  4. PrivateKey BIT STRING
  5. }
  6. AlgorithmIdentifier ::= SEQUENCE {
  7. algorithm OBJECT IDENTIFIER,
  8. parameters ANY DEFINED BY algorithm OPTIONAL
  9. }

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:

  1. -----BEGIN ENCRYPTED PRIVATE KEY-----
  2. BASE64 ENCODED DATA
  3. -----END ENCRYPTED PRIVATE KEY-----

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

  1. EncryptedPrivateKeyInfo ::= SEQUENCE {
  2. encryptionAlgorithm EncryptionAlgorithmIdentifier,
  3. encryptedData EncryptedData
  4. }
  5. EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
  6. EncryptedData ::= OCTET STRING

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

免责声明:文章转载自《RSA私钥和公钥文件格式 (pkcs#1, pkcs#8, pkcs#12, pem)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇[转] linux(debian)安装USB无线网卡(tp-link TL-WN725N rtl8188eu )windows环境之node.js安装与环境配置下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

jsrsasign 进行 RSA 加密、解密、签名、验签

通过谷歌, 发现jsrsasign库使用者较多. 查看api发现这个库功能很健全. 本文使用方法 公用代码: // 公钥 let pk="-----BEGIN PUBLIC KEY----- " + "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD3XSdz1MnzazBEN5KOfTx0Iy...

(5) openssl speed(测试算法性能)和openssl rand(生成随机数)

1.1 openssl speed 测试加密算法的性能 支持的算法有: openssl speed [md2] [mdc2] [md5] [hmac] [sha1] [rmd160] [idea-cbc] [rc2-cbc] [rc5-cbc] [bf-cbc] [des-cbc] [des-ede3] [rc4] [rsa512] [rsa1024] [...

php生成RSA公钥私钥方法-OPENSSL

一,环境 windows + php7.2 二,方法实现 $config = array('config' =>'D:phpwwwrootphpextrassslopenssl.cnf',  //安装PHP7会自带这个配置文件'digest_alg' => 'sha256',                 //可以用openssl_get_m...

【支付宝】"验签出错,sign值与sign_type参数指定的签名类型不一致:sign_type参数值为RSA,您实际用的签名类型可能是RSA2"

问题定位:从描述就可以看的出来了,你现在sign_type是  RSA类型的,要改成跟你现在用的签名类型一致的类型,也就是 要改为 RSA2 PHP为例 // 新版只支持此种签名方式 商户生成签名字符串所使用的签名算法类型,目前支持RSA  我的是在  AliConfi.php 里面有个方法里面有一行 $this->signType = 'RSA';...

.net中RSA加密解密

1、产生密钥: private static void CreateKey() { using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { string public...

git 配置多个SSH-Key

   我们在日常工作中会遇到公司有个gitlab,还有些自己的一些项目放在github上。这样就导致我们要配置不同的ssh-key对应不同的环境。下面我们来看看具体的操作: 1,生成一个公司用的SSH-Key      $ ssh-keygen -t rsa -C "youremail@yourcompany.com” -f ~/.ssh/id-rsa 在...