我正在尝试将p12(pfx(证书存储到ios上的密钥链中使用keychainswift的代码,只是klass从密码变成了证书:
@discardableResult
open func setCertificate(_ value: Data, forKey key: String,
withAccess access: KeychainSwiftAccessOptions? = nil) -> Bool {
// The lock prevents the code to be run simultaneously
// from multiple threads which may result in crashing
lock.lock()
defer { lock.unlock() }
deleteNoLock(key) // Delete any existing key before saving it
let accessible = access?.value ?? KeychainSwiftAccessOptions.defaultOption.value
let prefixedKey = keyWithPrefix(key)
var query: [String : Any] = [
KeychainSwiftConstants.klass : kSecClassCertificate,
KeychainSwiftConstants.attrAccount : prefixedKey,
KeychainSwiftConstants.valueData : value,
KeychainSwiftConstants.accessible : accessible
]
query = addAccessGroupWhenPresent(query)
query = addSynchronizableIfRequired(query, addingItems: true)
lastQueryParameters = query
lastResultCode = SecItemAdd(query as CFDictionary, nil)
return lastResultCode == noErr
}
获取-25303(无效属性为(我是否应该用不同的密钥分别零碎地存储身份、证书链和信任,以使其发挥作用?
考虑到我们有钥匙链沙盒而没有GUI?这是为了与macos的前向兼容性吗?
PS。苹果公司请尝试找到一位技术作家,他可以修复有关安全框架的可怕文档。谢谢
文档中提到了证书的所有可用属性。我相信你的attrAccount
是一个无效的参数,我觉得,但我不确定valueData
是否无效。因此,至少移除attrAccount
,并且可能移除valueData
。