Hello Apple Developer: I encountered some issues during development. I encrypted the secret key and stored it in the Keychain, but it failed when I tried to read it. I would like to ask if there is any problem with the code I wrote. Below is my code, including the storage and retrieval
NSMutableDictionary *query = [[NSMutableDictionary alloc] initWithObjectsAndKeys:(id)kSecClassGenericPassword,(id)kSecClass,
serviceID,(id)kSecAttrService,
@YES,(id)kSecReturnData,nil];
CFTypeRef dataTypeRef = NULL;
NSLog(@"SecItemCopyMatching");
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)(query), &dataTypeRef);
NSLog(@"SecItemCopyMatching end status = %d",status);
if (status == errSecSuccess) {
*privateData = CFBridgingRelease(dataTypeRef);
return 0;
}else{
return status;
}
NSMutableDictionary *attributespri = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
(id)kSecClassGenericPassword, (id)kSecClass,
serviceID, (id)kSecAttrService,
outData, (id)kSecValueData,
nil];
CFTypeRef dataRef = NULL;
OSStatus priStatus = SecItemAdd((__bridge CFDictionaryRef)attributespri, &dataRef);
if (dataRef) CFRelease(dataRef);
return priStatus == noErr;
Topic:
Privacy & Security
SubTopic:
General
5
0
197