如何从文件确定证书类型

发布于 2024-08-11 07:31:52 字数 150 浏览 4 评论 0原文

OpenSSL 证书似乎没有任何标准命名约定,因此我想知道是否有一个简单的命令可以获取有关任何 OpenSSL 证书的重要信息,无论其类型如何。我想至少知道证书类型(x509、RSA、DSA)以及它是公钥还是私钥。查看我刚刚从 PKCS12 文件中提取的证书的内容,这些都没有明确显示。

There doesn't seem to be any sort of standard naming convention for OpenSSL certificates, so I'd like to know if there's a simple command to get important information about any OpenSSL certificate, regardless of type. I'd like to know at least the certificate type (x509, RSA, DSA) and whether it's a public or private key. Looking at the contents of a certificate I just extracted from a PKCS12 file, neither of these are explicitly shown.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把昨日还给我 2024-08-18 07:31:53

首先,您遇到一些术语问题:

  • X509 标准定义了证书,RSA 和 DSA 是可在这些证书中使用的两种公钥算法;
  • 证书用于保存公钥,而不是私钥。
  • PKCS#12 是一个容器标准,可以保存 X509 客户端证书和相应的私钥,以及(可选)签署 X509 客户端证书的 CA 的 X509 证书。

因此,如果您正在检查 PKCS#12 文件(通常为 .p12 扩展名),那么您已经知道:

  • 它至少包含一个 X509 客户端证书,其中包含公钥;并且
  • 它包含相应的私钥。

您所不知道的是这些证书和信息是否有效。私钥是 RSA 或 DSA。您可以通过提取证书来检查这一点,然后检查它们:

openssl pkcs12 -in mycert.p12 -clcerts -nokeys -out mycert.crt
openssl x509 -in mycert.crt -text

openssl x509 命令的文本输出应包含 Subject Public Key 部分,其中包括可让您查看它是 RSA 还是 DSA 密钥(以及密钥大小)的字段。

Firstly, you have a few terminology problems:

  • the X509 standard defines certificates, and RSA and DSA are two of the public key algorithms that can be used in those certificates;
  • certificates are used to hold public keys, and never private keys.
  • PKCS#12 is a standard for a container which can hold an X509 client certificates and the corresponding private keys, as well as (optionally) the X509 certificates of the CAs that signed the X509 client certificate(s).

So, if you're examining a PKCS#12 file (typically .p12 extension), then you already know:

  • It contains at least one X509 client certificate, which contains a public key; and
  • It contains the corresponding private keys.

All you don't know is whether those certificate & private key are RSA or DSA. You can check this by extracting the certificate(s), and then examine them:

openssl pkcs12 -in mycert.p12 -clcerts -nokeys -out mycert.crt
openssl x509 -in mycert.crt -text

The text output of the openssl x509 command should include a Subject Public Key section, which will include fields that let you see if it's an RSA or DSA key (along with the key size).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文