Currently, I have an iOS app written in Swift that will be replaced by
a new version via Xamarin Forms. I am having trouble accessing the old
(Swift) Keychain, where ItemNotFound
is the only request code returned.
Both apps are using the same Bundle ID.
Here's the code I'm using:
byte[] _LegacyGetKeychainItem<T>(string key)
{
using (var record = ExistingRecordForKey(key))
using (var match = SecKeyChain.QueryAsData(record, false, out var resultCode))
{
if (resultCode == SecStatusCode.Success)
{
return match.ToArray();
}
}
throw new InvalidOperationException(string.Format("GetKeychainItem: data was null for key: {0}", key));
}
SecRecord ExistingRecordForKey(string key)
{
return new SecRecord(SecKind.GenericPassword)
{
Service = SEC_SERVICE, // Same as Bundle ID
Account = key
};
}