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).

        

         

目录
相关文章
|
Java 数据安全/隐私保护
Java 中使用 OpenSSL 生成公钥私钥进行数据加解密
Java 中使用 OpenSSL 生成公钥私钥进行数据加解密
1100 0
|
Java 测试技术 Maven
非对称密钥PKCS#1和PKCS#8格式互相转换(Java)
之前在 《前后端RSA互相加解密、加签验签、密钥对生成》 中提到过PKCS#1格式和PKCS#8格式密钥的区别以及如何生成密钥。实际有些场景中有可能也会涉及到前后端密钥格式不一致,这篇文章我们会讨论关于PKCS#1和PKCS#8格式密钥的互相转换。
非对称密钥PKCS#1和PKCS#8格式互相转换(Java)
|
SQL 数据可视化 关系型数据库
【大数据】可视化仪表板 - Superset的安装和使用
【大数据】可视化仪表板 - Superset的安装和使用
2827 0
|
网络协议 网络安全
|
存储 缓存 NoSQL
MySQL索引详解(一文搞懂)
索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息。
50958 17
MySQL索引详解(一文搞懂)
|
11月前
|
数据采集 人工智能 自然语言处理
Agentic Search: AI驱动的下一代企业搜索
Agentic Search是阿里云OpenSearch推出的AI搜索新范式,以智能体(Agent)为核心,融合深度检索、多步推理、工具调用与多模态理解,实现从“被动响应”到“主动执行”的跃迁。支持对话、规划、自适应三模式,覆盖问答、研究、客服、报告生成等全场景,助力企业知识库升级为动态业务引擎。
2561 2
Agentic Search: AI驱动的下一代企业搜索
|
9月前
|
弹性计算 API 数据安全/隐私保护
阿里云服务器如何续费?续费有没有优惠?通常具体有哪些优惠?
本文主要介绍阿里云服务器包年包月实例的续费方法,包括PC端、阿里云App端和API/CLI续费的具体步骤。同时,文章还探讨了续费优惠的类型及规则,如限时活动优惠、长期折扣政策、节省计划与预留实例券等,帮助用户最大化利用优惠,降低长期使用成本。此外,还介绍了续费过程中的注意事项,如自动续费限制、续费变配选项等,确保云服务器的稳定运行和数据安全。
|
安全 网络安全 Go
国密SSL协议之双证书体系
国密SSL协议使用双证书体系。本文描述了国密双证书体系的组成和差别,并描述了在U盾里面的使用情况。
7726 0
国密SSL协议之双证书体系
|
人工智能 安全 算法
HTTPS 的「秘钥交换 + 证书校验」全流程
HTTPS 通过“证书如身份证、密钥交换如临时暗号”的握手流程,实现身份认证与数据加密双重保障,确保通信安全可靠。
1590 0
|
Windows Linux
dietpi远程桌面与中文汉化教程
今天教大家dietpi系统汉化教程,当然如果你刷的不是dietpi也可以参照教程思路进行汉化.比如:armbian 固件下载链接:dietpi下载armbian下载如果你已经刷好固件了那么就开始吧! 1.
5205 0