.pem 文件是不是同时包含私钥和公钥?
Posted
技术标签:
【中文标题】.pem 文件是不是同时包含私钥和公钥?【英文标题】:Does .pem file contain both private and public keys?.pem 文件是否同时包含私钥和公钥? 【发布时间】:2011-11-24 06:34:55 【问题描述】:我想知道 PEM 文件是否同时包含私钥和公钥? “PEM”代表什么?
【问题讨论】:
相关:Convert pem key to ssh-rsa format 【参考方案1】:PEM 文件可能包含几乎任何内容,包括公钥、私钥或两者兼有,因为 PEM 文件不是标准文件。实际上,PEM 只是意味着该文件包含一个 base64 编码的数据位。它被称为 PEM 文件,暗指在 S/MIME 作为邮件安全标准之前的旧隐私增强邮件标准。这些标准以特定的 base64 格式指定了各种密钥和消息的格式。例如,请参阅RFC 1421。
通常,PEM 文件包含 base64 编码的密钥或证书,其页眉和页脚行格式为 -----BEGIN <whatever>-----
和 -----END <whatever>----
。随着时间的推移,<whatever>
出现了许多可能性,包括私钥、公钥、X509 证书、PKCS7 数据、包含多个证书的文件、同时包含私钥和 X509 证书的文件、PKCS#10 证书签名请求、.. .
RFC 7468 已被写入记录这种事实上的格式。
【讨论】:
感谢您解释缩写代表什么【参考方案2】:您可以使用以下命令将decode 您的PEM 格式化为x509 certificate:
openssl x509 -in cert.pem -text -noout
PEM 证书 contains 仅公钥或仅私钥或两者。
以下example:
-----BEGIN CERTIFICATE-----
MIICLDCCAdKgAwIBAgIBADAKBggqhkjOPQQDAjB9MQswCQYDVQQGEwJCRTEPMA0G
A1UEChMGR251VExTMSUwIwYDVQQLExxHbnVUTFMgY2VydGlmaWNhdGUgYXV0aG9y
aXR5MQ8wDQYDVQQIEwZMZXV2ZW4xJTAjBgNVBAMTHEdudVRMUyBjZXJ0aWZpY2F0
ZSBhdXRob3JpdHkwHhcNMTEwNTIzMjAzODIxWhcNMTIxMjIyMDc0MTUxWjB9MQsw
CQYDVQQGEwJCRTEPMA0GA1UEChMGR251VExTMSUwIwYDVQQLExxHbnVUTFMgY2Vy
dGlmaWNhdGUgYXV0aG9yaXR5MQ8wDQYDVQQIEwZMZXV2ZW4xJTAjBgNVBAMTHEdu
dVRMUyBjZXJ0aWZpY2F0ZSBhdXRob3JpdHkwWTATBgcqhkjOPQIBBggqhkjOPQMB
BwNCAARS2I0jiuNn14Y2sSALCX3IybqiIJUvxUpj+oNfzngvj/Niyv2394BWnW4X
uQ4RTEiywK87WRcWMGgJB5kX/t2no0MwQTAPBgNVHRMBAf8EBTADAQH/MA8GA1Ud
DwEB/wQFAwMHBgAwHQYDVR0OBBYEFPC0gf6YEr+1KLlkQAPLzB9mTigDMAoGCCqG
SM49BAMCA0gAMEUCIDGuwD1KPyG+hRf88MeyMQcqOFZD0TbVleF+UsAGQ4enAiEA
l4wOuDwKQa+upc8GftXE2C//4mKANBC6It01gUaTIpo=
-----END CERTIFICATE-----
你会得到:
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 0 (0x0)
Signature Algorithm: ecdsa-with-SHA256
Issuer: C = BE, O = GnuTLS, OU = GnuTLS certificate authority, ST = Leuven, CN = GnuTLS certificate authority
Validity
Not Before: May 23 20:38:21 2011 GMT
Not After : Dec 22 07:41:51 2012 GMT
Subject: C = BE, O = GnuTLS, OU = GnuTLS certificate authority, ST = Leuven, CN = GnuTLS certificate authority
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:52:d8:8d:23:8a:e3:67:d7:86:36:b1:20:0b:09:
7d:c8:c9:ba:a2:20:95:2f:c5:4a:63:fa:83:5f:ce:
78:2f:8f:f3:62:ca:fd:b7:f7:80:56:9d:6e:17:b9:
0e:11:4c:48:b2:c0:af:3b:59:17:16:30:68:09:07:
99:17:fe:dd:a7
ASN1 OID: prime256v1
NIST CURVE: P-256
X509v3 extensions:
X509v3 Basic Constraints: critical
CA:TRUE
X509v3 Key Usage: critical
Certificate Sign, CRL Sign
X509v3 Subject Key Identifier:
F0:B4:81:FE:98:12:BF:B5:28:B9:64:40:03:CB:CC:1F:66:4E:28:03
Signature Algorithm: ecdsa-with-SHA256
30:45:02:20:31:ae:c0:3d:4a:3f:21:be:85:17:fc:f0:c7:b2:
31:07:2a:38:56:43:d1:36:d5:95:e1:7e:52:c0:06:43:87:a7:
02:21:00:97:8c:0e:b8:3c:0a:41:af:ae:a5:cf:06:7e:d5:c4:
d8:2f:ff:e2:62:80:34:10:ba:22:dd:35:81:46:93:22:9a
要了解Public Key Algorithm
和Signature Algorithm
部分之间的区别,请阅读this(两者都是公开的)。
【讨论】:
以上是关于.pem 文件是不是同时包含私钥和公钥?的主要内容,如果未能解决你的问题,请参考以下文章