将 SecKeyRef、SecIdentityRefs 添加到 OS X 钥匙串
有方便的 SecCertificateAddToKeychain() 函数,它允许开发人员添加“浮动”证书(例如由 SecCertificateCreateWithData() 生成的 SecCertificateRef 实例)到钥匙扣。
SecKeyRef
和 SecIdentityRef
实例的等效函数在哪里?有SecKeychainItemImport()
,但它用于导入原始数据。还有SecItemAdd()
,但它仅限于添加密码。
我缺少什么?
There exists the handy SecCertificateAddToKeychain()
function, which allows a developer to add "floating" certificates (e.g. SecCertificateRef
instances generated by SecCertificateCreateWithData()
) to a keychain.
Where are the equivalent functions for SecKeyRef
and SecIdentityRef
instances? There is SecKeychainItemImport()
, but it's for importing raw data. There is also SecItemAdd()
, but it's limited to adding passwords.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SecItemAdd
非常有能力将证书和密钥添加到钥匙串中;只需将kSecClass
属性设置为项目的类(例如kSecClassKey),并在kSecUseItemList
属性中以数组形式传递项目引用即可。唯一需要注意的是,对 SecItemAdd 的一次调用只能添加同一类的项目;如果要添加证书和密钥,则需要分两次调用来完成。
您不需要显式创建或添加身份到钥匙串;它们是当证书及其私钥都可用时自动创建的隐式构造。
SecItemAdd
is quite capable of adding certificates and keys to a keychain; just set thekSecClass
attribute to the item's class (e.g. kSecClassKey) and pass the item references in an array in thekSecUseItemList
attribute.The only caveat is that a single call to
SecItemAdd
can only add items of the same class; if you want to add a certificate and a key, you need to do it in two calls.You don't need to explicitly create or add identities to a keychain; they are implicit constructs that are automatically created when both the certificate and its private key are available.