这是哪种私钥格式?
我有一个使用 OpenSSL 制作并使用 RSA 加密的私钥,如下所示:
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQILJ8rNTk54VICAggA
MBQGCCqGSIb3DQMHBAiXuThuf12hMwSCBMhrm8H2j7yzLBOIvSWbLoyUmIn7e9zA
6PLDzj1dos+h+wAkPN0IgJlkdoBBXlnF7tzGdoctOYOKiu/p+HLzMnvHaDfNSFwz
5zx4yyZsKtf90gT6IVuJy7TMiLK3gk4gdZJc820OeRr1FjdRV3iVpTXbVfpwG/B3
IbV0PX3ZaHeR1m8vWI0/XQB7ZL7lLT+3MO66X/PAMTPA9joFMxuPFasIb2uXSqe/
CJNOyY4iW89uYHFiOe53e4ggUdT/rupoR4OSNKKEH5f1y+FIuH1xNvlmi14hJn+k
KOOi89vVIcvh4abCM+jhYwpPOGB8Sz2bAXsYocgZPvKtKakHlis7RcSsd5Usx9Nt
tgQ=
-----END ENCRYPTED PRIVATE KEY-----
我已将其存储到 user.key
文件中。
实际上我正在用 Objective-C 实现一个 CMS 加密和解密项目。现在我正在尝试使用证书、私钥等解密我的加密容器文件... 我有点困惑应该选择 OpenSSL 中的哪种方法将上述密钥加载到 EVP_PKEY
对象中。
它建议我使用以下格式:
- FORMAT_ASN1
- FORMAT_PEM
- FORMAT_PKCS12
- FORMAT_MSBLOB
- FORMAT_PVK
我知道它不是 PEM
和 PKCS12
。我猜是 ASN1
或 PVK
但我真的不知道,而且我没有在 OpenSSL 文档中找到任何关于此的进一步信息。
谁能告诉我上述密钥的格式是什么?
编辑: 为了更具体地说明我的问题:我将上述密钥加载到 BIO
中。我可以使用 BIO_read(keybio, ...)
成功读取此 BIO
并且它包含密钥(以 ascii 格式)。现在我想从此 BIO
获取 EVP_PKEY
。 我试过了……
EVP_PKEY *key = PEM_read_bio_PrivateKey(keybio, NULL, 0, NULL);
但这行不通。当我调用它时,它要求我在控制台中输入密码,当我这样做时,密钥是NULL
。 :-/
I've a private key made with OpenSSL and encrypted with RSA like this:
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQILJ8rNTk54VICAggA
MBQGCCqGSIb3DQMHBAiXuThuf12hMwSCBMhrm8H2j7yzLBOIvSWbLoyUmIn7e9zA
6PLDzj1dos+h+wAkPN0IgJlkdoBBXlnF7tzGdoctOYOKiu/p+HLzMnvHaDfNSFwz
5zx4yyZsKtf90gT6IVuJy7TMiLK3gk4gdZJc820OeRr1FjdRV3iVpTXbVfpwG/B3
IbV0PX3ZaHeR1m8vWI0/XQB7ZL7lLT+3MO66X/PAMTPA9joFMxuPFasIb2uXSqe/
CJNOyY4iW89uYHFiOe53e4ggUdT/rupoR4OSNKKEH5f1y+FIuH1xNvlmi14hJn+k
KOOi89vVIcvh4abCM+jhYwpPOGB8Sz2bAXsYocgZPvKtKakHlis7RcSsd5Usx9Nt
tgQ=
-----END ENCRYPTED PRIVATE KEY-----
And I've stored it into a user.key
file.
Actually I'm implementing a CMS encrypt and decrypt project in objective-c. Now I'm trying to decrypt my encrypted container file using certificates, private key, and so on...
I'm a little bit confused which method from OpenSSL I should choose to load the aforementioned key into an EVP_PKEY
object.
It suggests me the following formats:
- FORMAT_ASN1
- FORMAT_PEM
- FORMAT_PKCS12
- FORMAT_MSBLOB
- FORMAT_PVK
I know that it's not PEM
and PKCS12
. I would guess ASN1
or PVK
but I really don't know and I haven't found any further information on this in the OpenSSL docu.
Can anyone tell me please which format the aforementioned key has?
EDIT:
To specify my question a bit more: I have the aforementioned key loaded into a BIO
. I can read this BIO
with BIO_read(keybio, ...)
successfully and it contains the key (in ascii). Now I want to get an EVP_PKEY
from this BIO
.
I've tried...
EVP_PKEY *key = PEM_read_bio_PrivateKey(keybio, NULL, 0, NULL);
... but this doesn't work. When I call this it asks me to enter the passphrase in the console and when I do this, the key is NULL
. :-/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
密钥是封装在 PEM 中的 PKCS#8 EncryptedPrivateKeyInfo-容器。
您可以执行以下操作将其放入
EVP_PKEY
对象中:The key is a PKCS#8 EncryptedPrivateKeyInfo wrapped in a PEM-container.
You can do something like this to get it into an
EVP_PKEY
-object:OpenSSL 使用该(扩展)PEM 格式来存储 PKCS#8 编码的私钥。
That (extended) PEM format is used by OpenSSL for PKCS#8 encoded private keys.