Post

Replies

Boosts

Views

Activity

Cannot get symmetric key from keychain
Hello,Try to create and retreive a symmetric key from keychain :add the key-----------------------------------let key = Data.init(repeating: 0xee, count: 32)let name = "test"let attributes = [kSecAttrKeyType: kSecAttrKeyTypeAES, kSecAttrKeySizeInBits: NSNumber.init(value: 256)] as CFDictionary var error: Unmanaged<CFError>?let secKey = SecKeyCreateFromData(attributes, key as CFData, &error) let addquery = [kSecClass: kSecClassKey, kSecAttrKeyClass: kSecAttrKeyClassSymmetric, kSecAttrLabel: name, kSecValueRef: secKey!] as CFDictionary let status = SecItemAdd(addquery as CFDictionary, nil)if status != errSecSuccess{ print(SecCopyErrorMessageString(status, nil)!)}-----------------------------------The keychain item is createdGet the key-----------------------------------let name = "test"let getquery = [kSecClass: kSecClassKey, kSecAttrKeyClass: kSecAttrKeyClassSymmetric, kSecAttrLabel: name] as [CFString : Any] var secKey: CFTypeRef?let status = SecItemCopyMatching(getquery as CFDictionary, &secKey) if status == errSecSuccess{ if let dic = SecKeyCopyAttributes(secKey as! SecKey) as? [CFString: Any] { if let key = dic[kSecValueData] { print("Ok") } else { print("Cannot get the key") } } else { print("Error retrieving dictionnary") }}else{ print(SecCopyErrorMessageString(status, nil)!)}-----------------------------------If the key is added and retreive in the same process it works. The number of elements in the dic is 21.But if later (in another process) i try to get the key stored in keychain i get the dictionnary but not the key. The number of elements in the dic is 20 (kSecValueData is missing).What parameters are missing to get the key ?Thank you
3
0
924
Jun ’20