简体   繁体   English

如何将证书导入 iOS 钥匙串?

[英]How can I import a certificate into the iOS keychain?

I tried the following code but I keep getting "The specified attribute does not exist" error.我尝试了以下代码,但我不断收到“指定的属性不存在”错误。 kSecValueRef was checked and is not nil kSecValueRef 已检查并且不为零

let attributes: [String: Any] = [kSecClass as String : kSecClassCertificate,
                                 kSecValueRef as String : certificateRef!,
                                 kSecAttrApplicationTag as String : tag]

let osStatus = SecItemAdd(attributes as CFDictionary, nil)

You can find the resource describing available attributes for the kSecClassCertificate type here .您可以在此处找到描述kSecClassCertificate类型的可用属性的资源。 You should change kSecAttrApplicationTag to kSecAttrLabel , that should solve the issue for you.您应该将kSecAttrApplicationTag更改为kSecAttrLabel ,这应该可以为您解决问题。 The application tag is not a valid parameter for a certificate.应用程序标签不是证书的有效参数。

ps There is a document describing each of these attributes per class on the Apple developer documentation page, or you could also look at the source code . ps 在 Apple 开发人员文档页面上有一个文档描述了每个 class 的每个属性,或者您也可以查看源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM