Cannot save Security Item to Keychain

Home / Uncategorized / Cannot save Security Item to Keychain

Question:
I am trying to save SecIdentity item into the keychain using Swift 3. After saving status of operation is alway 0 (Successful), but when I try to retrieve the saved one, status is -25300 (which means that object does not exist) What I’m doing wrong?
func saveIdentity(identity: SecIdentity) -> Data? {
let str = "identity"

let saveQuery = [
kSecClass as String : kSecClassIdentity,
kSecValueRef as String : identity,
kSecAttrLabel as String : "identity",
kSecAttrAccessible as String : kSecAttrAccessibleAlways
] as [String : Any]

var item: CFTypeRef? = nil

var status: OSStatus = SecItemAdd(saveQuery as CFDictionary, nil)
// Status = 0
let loadQuery = [
kSecClass as String : kSecClassIdentity,
kSecAttrLabel as String : "identity",
kSecReturnRef as String : kCFBooleanTrue,
kSecMatchLimit as String : kSecMatchLimitAll
] as [String : Any]

status = SecItemCopyMatching(loadQuery as CFDictionary, &item)
// Status = -25300
if status == noErr {
return item as! Data?
} else {
return nil
}
}


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *