openssl - 什么是公钥 header 和公钥信息?

标签 openssl cryptography rsa

我正在尝试查找什么是公钥 header 和公钥信息。我使用 openssl 以及公钥模数转储了 C 格式的证书。它将公钥信息和公钥 header 列为公钥。但我无法使用 openssl.exe rsa -pubin -inform DER -text -noout < publickey.der 转储这些字段用于在我的服务器上生成的公钥。

谁能解释一下数字证书中这些字段的意义是什么,它们对所有公钥都一样吗?无法在 openssl 上获取此信息,只是提到 DER 编码将具有额外的页眉和页脚。

最佳答案

我从未听说过公钥 header ...您能举个例子吗?

公钥信息可能是 X.509 证书中公钥通常编码的标准方式,格式为 SubjectPublicKeyInfo attribute .这些 SubjectPublicKeyInfos 可以变成一个公钥文件(我假设这就是你想要做的?如果我错了请纠正我!)该部分还告诉你在哪里可以找到有关特定算法的信息,他们引用了 RSA RFC 3279 . SubjectPublicKeyInfo 定义如下:

SubjectPublicKeyInfo  ::=  SEQUENCE  {
    algorithm            AlgorithmIdentifier,
    subjectPublicKey     BIT STRING  } 

RFC 3279 说:

The rsaEncryption OID is intended to be used in the algorithm field of a value of type AlgorithmIdentifier. The parameters field MUST have ASN.1 type NULL for this algorithm identifier.

进一步:

The RSA public key MUST be encoded using the ASN.1 type RSAPublicKey:

  RSAPublicKey ::= SEQUENCE {
     modulus            INTEGER,    -- n
     publicExponent     INTEGER  }  -- e

因此它是包含相关数据的 subjectPublicKey 字段 - 例如,您可以使用 OpenSSL 的 x509 命令获取这些值:

openssl x509 -in certificate.cer -inform DER -noout -text

打印出来(对于 PEM 证书,删除 -inform DER):

Subject Public Key Info:
        Public Key Algorithm: rsaEncryption
            Public-Key: (1024 bit)
            Modulus:
                00:cb:c2:...
            Exponent: 65537 (0x10001)

还有一个巧妙的技巧,您可以使用 x509 直接生成 PEM RSA 公钥文件:

openssl x509 -inform DER -in certificate.cer -pubkey -noout > pubkey.pem

并且您的公钥以 PEM 编码导出。

关于openssl - 什么是公钥 header 和公钥信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10812588/

相关文章:

node.js - NodeJS 加密 RSA,与 Elixir/Erlang PublicKey 不兼容?

swift - 使用 Swift 获取 RSA 私钥的 n 和 d

node.js 加密签名和 openssl 签名不匹配

c++ - 在 Windows x64 上设置 openssl 时找不到 libeay32.lib 和 ssleay32.lib 文件

java - SHA1 和 RSA 与 java.security.Signature 对比 MessageDigest 和 Cipher

算法 "PBE WITH MD5 AND 256 BIT AES-CBC-OPENSSL"的 java.security.NoSuchAlgorithmException

.net - 如何使用 .NET Framework 执行 RSAES-OAEP 加密和解密?

ssl - OpenSSL:使用 `openssl req` 明确设置开始/结束日期?

XCode 在/usr/include 中找不到 OpenSSL header

ruby-on-rails - 如何在 Ubuntu 上更改 OPENSSLDIR?