public void SetToken(string token) { byte[] password_bytes = Encoding.UTF8.GetBytes(token); SecStatusCode result = SecKeyChain.AddGenericPassword( SERVICE, ACCOUNT, password_bytes); if (result == SecStatusCode.DuplicateItem) { // TODO: Replace the token // SecKeyChain.Remove (); // StoreToken (token); return; } if (result != SecStatusCode.Success) { throw new Exception("Could not store token in Keychain"); } }
public static void SaveCredentialToKeychain(string username, string password) { SecStatusCode code = SecStatusCode.NotAvailable; byte[] passwordBytes; code = SecKeyChain.FindGenericPassword(ServiceName, username, out passwordBytes); if (code == SecStatusCode.Success) { code = SecKeyChain.Update(new SecRecord(SecKind.GenericPassword) { Service = ServiceName, Account = username }, new SecRecord(SecKind.GenericPassword) { Account = username, ValueData = NSData.FromString(password) }); } else { code = SecKeyChain.AddGenericPassword(ServiceName, username, System.Text.Encoding.UTF8.GetBytes(password)); } }
public override void Add(string key, string value) { SecKeyChain.AddGenericPassword(ApplicationName, key, Encoding.UTF8.GetBytes(value)).AndThrowExceptionOnFailure(); }