我正在尝试根据mbinna问题更新我的钥匙串项目的 kSecAttrAccessible。
问题是以下代码为updateItemStatus
变量返回 -50。我查看了一个关于它的类似问题,然后kSecReturnRef
从我的查询 () 中删除了该属性newQuery
,但它仍然无法正常工作并返回 -50,这意味着“传递给函数的一个或多个参数无效”。
我究竟做错了什么?
NSString *privateKeyAttrTag = @"mykeytag";
NSDictionary *getQuery = [NSDictionary dictionaryWithObjectsAndKeys:
kSecClassKey, kSecClass,
privateKeyAttrTag, kSecAttrApplicationTag,
kSecAttrKeyTypeRSA, kSecAttrKeyType,
@YES, kSecReturnRef,
kSecAttrAccessibleWhenUnlocked, kSecAttrAccessible, nil];
CFTypeRef dataTypeRef = NULL;
OSStatus status = SecItemCopyMatching(
(__bridge CFDictionaryRef)getQuery, &dataTypeRef);
if (status==errSecSuccess && dataTypeRef != NULL) {
NSData *data = (__bridge NSData *)dataTypeRef;
NSDictionary *newQuery = [NSDictionary dictionaryWithObjectsAndKeys:
kSecClassKey, kSecClass,
privateKeyAttrTag, kSecAttrApplicationTag,
kSecAttrKeyTypeRSA, kSecAttrKeyType,
kSecAttrAccessibleWhenUnlocked, kSecAttrAccessible, nil];
NSDictionary *updateAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
kSecAttrAccessibleAfterFirstUnlock, kSecAttrAccessible,
(CFDataRef)data, kSecValueData, nil];
OSStatus updateItemStatus = SecItemUpdate(
(__bridge CFDictionaryRef)newQuery, (__bridge CFDictionaryRef)updateAttrs);
// updateItemStatus == -50, which means "One or more parameters passed to a function were not valid."
}