Example #1
0
		public static void AddCredentials()
		{
			Console.WriteLine ("Attempting to Add Credentials");
			var token = AppCache.Instance.Ticket.refresh_token;

			var secObject = new SecAccessControl (SecAccessible.WhenPasscodeSetThisDeviceOnly, SecAccessControlCreateFlags.UserPresence);

			var securityRecord = new SecRecord (SecKind.GenericPassword) {
				Service = "TextShield",
				ValueData = new NSString (token).Encode (NSStringEncoding.UTF8),
				UseNoAuthenticationUI = true,
				AccessControl = secObject
			};

			DispatchQueue.MainQueue.DispatchAsync (() => {
				SecStatusCode status = SecKeyChain.Add (securityRecord);
				Console.WriteLine("Credential Add Status: " + status.ToString());
			});
		}
		private void AddItemAsync ()
		{
			var secObject = new SecAccessControl (SecAccessible.WhenPasscodeSetThisDeviceOnly, SecAccessControlCreateFlags.UserPresence);

			if (secObject == null) {
				string message = Text.CANT_CREATE_SEC_OBJ;
				Console.WriteLine (message);
				textView.Text += string.Format (Text.SEC_ITEM_ADD_CAN_CREATE_OBJECT, message);
			}

			var securityRecord = new SecRecord (SecKind.GenericPassword) {
				Service = Text.SERVICE_NAME,
				ValueData = new NSString (Text.SECRET_PASSWORD_TEXT).DataUsingEncoding (NSStringEncoding.UTF8),
				UseNoAuthenticationUI = true,
				AccessControl = secObject
			};

			DispatchQueue.MainQueue.DispatchAsync (() => {
				SecStatusCode status = SecKeyChain.Add (securityRecord);

				var message = string.Format (Text.SEC_ITEM_ADD_STATUS, status.GetDescription ());
				PrintResult (textView, message);
			});
		}