我正在尝试获取钥匙串项目的属性。此代码应查找所有可用属性,然后打印出它们的标签和内容。
根据文档,我应该看到像“cdat”这样的标签,但它们只是看起来像一个索引(即第一个标签是 0,下一个是 1)。这使它变得毫无用处,因为我无法分辨出哪个属性是我正在寻找的属性。
SecItemClass itemClass;
SecKeychainItemCopyAttributesAndData(itemRef, NULL, &itemClass, NULL, NULL, NULL);
SecKeychainRef keychainRef;
SecKeychainItemCopyKeychain(itemRef, &keychainRef);
SecKeychainAttributeInfo *attrInfo;
SecKeychainAttributeInfoForItemID(keychainRef, itemClass, &attrInfo);
SecKeychainAttributeList *attributes;
SecKeychainItemCopyAttributesAndData(itemRef, attrInfo, NULL, &attributes, 0, NULL);
for (int i = 0; i < attributes->count; i ++)
{
SecKeychainAttribute attr = attributes->attr[i];
NSLog(@"%08x %@", attr.tag, [NSData dataWithBytes:attr.data length:attr.length]);
}
SecKeychainFreeAttributeInfo(attrInfo);
SecKeychainItemFreeAttributesAndData(attributes, NULL);
CFRelease(itemRef);
CFRelease(keychainRef);