问题
I've created a new question for this since this is more linked to Xamarin. I was looking for a way to uniquely identify a device in iOS when I stumbled upon this question in StackOverflow. It took me a while to figure out how to add anything into Keychain and them I stumbled upon this question.
After all the stumbling, I came up with this piece of code for generating the unique token.
var s = new SecRecord(SecKind.GenericPassword)
{
AccessGroup = "kSecAttrAccessGroupToken",
ValueData = NSData.FromString(value),
Generic = NSData.FromString(key)
};
SecKeyChain.Add(s);
Now the problem is that even though I'm adding this entry to keychain I am unable to find it. I'm also interested to know if I am using the kSecAttrAccessGroupToken correctly.
My Enlistments.plist file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>keychain-access-groups</key>
<array>
<string>my app id</string>
<string>kSecAttrAccessGroupToken</string>
</array>
</dict>
</plist>
回答1:
kSecAttrAccessGroupToken
is writable only by CryptoTokenKit smart card drivers. Apps can query the keychain using that attribute in order to find items stored on a particular smart card. This attribute is not for any other use.
There was a bug in 10.3.x beta that would allow any app to also write to it, but that has been patched.
Re: https://forums.developer.apple.com/thread/72271
来源:https://stackoverflow.com/questions/46396533/xamarin-ios-add-value-to-keychain-which-can-be-accessed-by-all-apps-on-device