我尝试在 C 库中管理 PKCS#12 结构中的多个 RSA 密钥和证书。使用原语管理单个键PKCS12_create
并且PKCS12_parse
工作正常,但我找不到有关管理多个键的任何内容。我尝试使用保险箱和包原语,但我只成功破坏了我的 PKCS12。
OpenSSL 的 PKCS#12 是否允许 PKCS#12 结构中的多个密钥和证书?如果是这样,那么如何使用 PKCS#12 API 管理多个密钥和证书?
谢谢大家
PKCS#12 is a complicated data structure. All of the operations that PKCS12_parse
use are public API, it just tries to simplify the simple case. The entire 245 lines of p12_kiss.c (one presumes Keep It Simple, Stupid) are PKCS12_parse and its (non-public) helper routines.
p12_crt.c is another 291 lines of "man, this file format is complicated", which is just PKCS12_create
.
Managing multiple files is easier code, but if you want to take the complexity into your code you can simplify your file operations.
Don't forget to call PKCS12_SAFEBAG_create_pkcs8_encrypt
on the private key bags. Your keys aren't encrypted unless you call it, and (IIRC) Apple's PFX reader won't load keys out of unencrypted bags (probably not an intentional decision, they just likely never experienced it).
我终于成功地添加/解析了多个 RSA 密钥,并且它们从 PKCS12 结构/文件中获得证书。我的解析函数基于文件中的 OpenSSLparse_pk12
函数p12_kiss.c
。这个函数似乎只返回最后一个包。我调整它以检查每个包的友好名称并返回匹配的那个。
添加功能首先(STACK_OF(PKCS7))
从现有的 PKCS12 中打开保险箱,然后处理此保险箱,以便向其中添加新的一叠袋子。然后,我使用该功能创建一个新的 PKCS12PKCS12_add_safes
并删除前一个。谢谢大家