Пример #1
0
        private async Task <bool> Authenticate()
        {
            var callback           = new SimpleAuthCallbacks();
            var context            = Android.App.Application.Context;
            var isUsingFingerprint = ContextCompat.CheckSelfPermission(context, Manifest.Permission.UseFingerprint);

            if (isUsingFingerprint == Permission.Granted)
            {
                var cancellationSignal = new Android.Support.V4.OS.CancellationSignal();
                var cryptHelper        = new CryptoObjectHelper();
                var fingerprintManager = FingerprintManagerCompat.From(context);
                fingerprintManager.Authenticate(
                    cryptHelper.BuildCryptoObject(),
                    (int)FingerprintAuthenticationFlags.None, /* flags */
                    cancellationSignal,
                    callback,
                    null
                    );
            }

            while (callback.IsWaiting)
            {
                await Task.Delay(87);
            }

            return(callback.Status == SimpleAuthCallbacks.AuthenticateResult.Success);
        }
Пример #2
0
        public void AuthenticateAndroid(string reason)
        {
            // CryptoObjectHelper is described in the previous section.
            var cryptoHelper = new CryptoObjectHelper();

            var context = Android.App.Application.Context;
            //if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
            //{
            //    /* ==================================================================================================
            //     * android api 23 or higher
            //     * ================================================================================================*/
            //    var manager = context.GetSystemService(Context.FingerprintService) as FingerprintManager;
            //    // cancellationSignal can be used to manually stop the fingerprint scanner.
            //    var cancellationSignal = new Android.OS.CancellationSignal();
            //    var authenticationCallback = new SimpleAuthCallback();
            //    // Start the fingerprint scanner.
            //    manager.Authenticate(cryptoHelper.BuildCryptoObject(), cancellationSignal, FingerprintAuthenticationFlags.None, authenticationCallback, null);
            //    return;
            //}

            // Using the Android Support Library v4
            var managerCompat = FingerprintManagerCompat.From(context);
            // cancellationSignal can be used to manually stop the fingerprint scanner.
            var cancellationSignalCompat = new Android.Support.V4.OS.CancellationSignal();
            // AuthenticationCallback is a base class that will be covered later on in this guide.
            var callbackCompat = new SimpleCompatAuthCallback();

            // Start the fingerprint scanner.
            managerCompat.Authenticate(cryptoHelper.BuildCompatCryptoObject(), 0, cancellationSignalCompat, callbackCompat, null);
            //return new LocalAuthResult(false);
            //return Task.FromResult(new LocalAuthResult(false));
        }
        public void Authenticate(Action successAction, Action failAction)
        {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(Android.App.Application.Context);
            const int          flags        = 0; /* always zero (0) */
            CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
            // Using the Support Library classes for maximum reach
            FingerprintManagerCompat fingerPrintManager = FingerprintManagerCompat.From(Android.App.Application.Context);

            // AuthCallbacks is a C# class defined elsewhere in code.
            FingerprintManagerCompat.AuthenticationCallback authenticationCallback = new AuthenticationCallBack();

            var page = new FingerprintAuthenticationPage((int)Android.OS.Build.VERSION.SdkInt);

            Xamarin.Forms.Application.Current.MainPage.Navigation.PushPopupAsync(page);

            MessagingCenter.Subscribe <string, string>("FingerprintAuthentication", "Authenticate", (sender, arg) =>
            {
                string result = arg;

                if (arg == "true")
                {
                    MessagingCenter.Unsubscribe <string, string>("FingerprintAuthentication", "Authenticate");
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Xamarin.Forms.Application.Current.MainPage.Navigation.PopPopupAsync();
                    });
                    //Do the thing when success to pass
                    if (successAction != null)
                    {
                        successAction.Invoke();
                    }
                }
                else if (arg == "false")
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        page.SetFailLabelText("Fail to authenticate!");
                    });
                }
                else
                {
                    MessagingCenter.Unsubscribe <string, string>("FingerprintAuthentication", "Authenticate");
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Xamarin.Forms.Application.Current.MainPage.Navigation.PopPopupAsync();
                    });
                    //Do the thing when fail to pass
                    if (failAction != null)
                    {
                        failAction.Invoke();
                    }
                }
            });



            cancellationSignal = new Android.Support.V4.OS.CancellationSignal();
            // Here is where the CryptoObjectHelper builds the CryptoObject.
            fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(), flags, cancellationSignal, authenticationCallback, null);
        }
 public FingerprintDialog(DialogConfiguration dialogConfiguration, FingerprintManagerCompat.AuthenticationCallback authenticationCallBack, Android.Support.V4.OS.CancellationSignal fingerprintCancellationSignal)
 {
     _dialogConfiguration           = dialogConfiguration;
     _authenticationCallBack        = authenticationCallBack;
     _fingerprintCancellationSignal = fingerprintCancellationSignal;
     ((AuthenticationCallBack)_authenticationCallBack).SetFingerprintDialog(this);
 }
            public override void OnAuthenticationError(int errMsgId, ICharSequence errString)
            {
                bool   reportError = (errMsgId == (int)FingerprintState.ErrorCanceled);
                string debugMsg    = $"OnAuthenticationError: {errMsgId}:`{errString}`.";

                if (reportError)
                {
                    debugMsg += (errMsgId, errString.ToString());
                    debugMsg += " Reporting the error.";
                }
                else
                {
                    debugMsg += " Ignoring the error.";
                }

                Console.WriteLine(debugMsg);
                if (_tcsWeak.TryGetTarget(out var tcs))
                {
                    tcs.TrySetResult(new AuthenticationResult(false, debugMsg));
                }

                _cancellationSignal?.Cancel();
                _cancellationSignal?.Dispose();
                _cancellationSignal = null;

                _dialog.Dismiss();
            }
Пример #6
0
        public void GetFingerprint(EventHandler evt, bool encrypt, byte[] data)
        {
            //make sure the device is secured
            KeyguardManager keyguardManager = (KeyguardManager)Application.Context.GetSystemService(Context.KeyguardService);

            if (!keyguardManager.IsKeyguardSecure)
            {
                return;
            }
            //make sure fingerprints are enrolled
            if (!m_fingerprintManager.HasEnrolledFingerprints)
            {
                return;
            }
            //check permissions
            Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.UseFingerprint);
            if (permissionResult != Android.Content.PM.Permission.Granted)
            {
                return;
            }

            m_evt  = evt;
            m_data = data;
            m_mode = encrypt ? CipherMode.EncryptMode : CipherMode.DecryptMode;

            CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();

            cancellationSignal = new Android.Support.V4.OS.CancellationSignal();

            //prompt user to scan their fingerprint
            m_fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(m_mode), 0, cancellationSignal, this, null);
        }
Пример #7
0
 internal void CancelAuthentication()
 {
     cancellationSignal?.Cancel();
     newCancelSignal?.Cancel();
     newCancelSignal    = null;
     cancellationSignal = null;
 }
Пример #8
0
        private void LogUserIn()
        {
            var cancellation = new Android.Support.V4.OS.CancellationSignal();

            FingerprintManagerCompat.AuthenticationCallback authenticationCallback = new AuthenticationCallback(this, userId);
            Toast.MakeText(this, "Поднесите палец к сенсору", ToastLength.Long).Show();
            fingerprintManager.Authenticate(null, 0, cancellation, authenticationCallback, null);
        }
 /// <summary>
 /// Stops the authentication.
 /// </summary>
 public void StopAuthentication()
 {
     if (mCancellationSignal != null)
     {
         mCancellationSignal.Cancel();
         mCancellationSignal = null;
     }
 }
 protected void CancelledDialogDelegate(object sender, DialogClickEventArgs e)
 {
     if (_tcsWeak.TryGetTarget(out var tcs))
     {
         tcs.TrySetResult(new AuthenticationResult(false, "Biometric authentication scan was cancelled"));
     }
     _cancellationSignal?.Cancel();
     _cancellationSignal = null;
 }
 public SimpleAuthCallbacks(
     IDialogInterface dialog,
     WeakReference <TaskCompletionSource <AuthenticationResult> > tcsWeak,
     CancellationSignal cancellationSignal)
 {
     _dialog             = dialog;
     _tcsWeak            = tcsWeak;
     _cancellationSignal = cancellationSignal ?? new CancellationSignal();
 }
 internal FingerprintManagerFragment(string alertTitle, string alertMessage, TaskCompletionSource <AuthenticationResult> tcs)
 {
     _fingerprintManager = FingerprintManagerCompat.From(MainApplication.CurrentActivity);
     _alertTitle         = alertTitle;
     _alertMessage       = alertMessage;
     _cryptObjectHelper  = new CryptoObjectHelper();
     _cancellationSignal = new CancellationSignal();
     _tcsWeak            = new WeakReference <TaskCompletionSource <AuthenticationResult> >(tcs);
 }
 void StopListeningForFingerprints(bool butStartListeningAgainInOnResume = false)
 {
     if (cancellationSignal != null)
     {
         cancellationSignal.Cancel();
         cancellationSignal = null;
     }
     ScanForFingerprintsInOnResume = butStartListeningAgainInOnResume;
 }
 void StopListeningForFingerprints(bool butStartListeningAgainInOnResume = false)
 {
     if (_cancellationSignal != null)
     {
         _cancellationSignal.Cancel();
         _cancellationSignal = null;
         Log.Debug(TAG, "StopListeningForFingerprints: _cancellationSignal.Cancel();");
     }
     ScanForFingerprintsInOnResume = butStartListeningAgainInOnResume;
 }
Пример #15
0
 public override async Task <SecureFingerprintAuthenticationResult> AuthenticateSecureNoDialogAsync(IAuthenticationFailedListener failedListener, string key, CancellationToken cancellationToken)
 {
     using (var cancellationSignal = new Android.Support.V4.OS.CancellationSignal())
         using (cancellationToken.Register(() => cancellationSignal.Cancel()))
         {
             CryptoObjectHelper crypto = new CryptoObjectHelper();
             var callback = new SecureFingerprintAuthenticationCallback(failedListener, key);
             GetServiceCompat().Authenticate(crypto.BuildCryptoObject(), (int)FingerprintAuthenticationFlags.None, cancellationSignal, callback, null);
             return(await callback.GetTask());
         }
 }
        public override void OnResume()
        {
            base.OnResume();
            if (!ScanForFingerprintsInOnResume)
            {
                return;
            }

            UserCancelledScan   = false;
            _cancellationSignal = new CancellationSignal();
            _fingerprintManager.Authenticate(CryptObjectHelper.BuildCryptoObject(),
                                             (int)FingerprintAuthenticationFlags.None,  /* flags */
                                             _cancellationSignal,
                                             new SimpleAuthCallbacks(this),
                                             null);
        }
Пример #17
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            fingerprintManager = FingerprintManagerCompat.From(this);
            cancellation       = new Android.Support.V4.OS.CancellationSignal();
            preferences        = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            emailEditText    = FindViewById <EditText>(Resource.Id.emailEditText);
            passwordEditText = FindViewById <EditText>(Resource.Id.passwordEditText);
            signinButton     = FindViewById <Button>(Resource.Id.signinButton);
            registerButton   = FindViewById <Button>(Resource.Id.registerButton);

            signinButton.Click   += SigninButton_Click;
            registerButton.Click += RegisterButton_Click;
        }
Пример #18
0
        public Task <bool> Scan()
        {
            tcs = new TaskCompletionSource <bool>();
            var Context = Android.App.Application.Context;
            // Using the Android Support Library v4
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(Context);


            if (!fingerprintManager.IsHardwareDetected)
            {
                Toast.MakeText(Context, "FingerPrint authentication permission not enable", ToastLength.Short).Show();
                tcs.SetResult(false);
                return(tcs.Task);
            }

            if (!fingerprintManager.HasEnrolledFingerprints)
            {
                Toast.MakeText(Context, "Register at least one fingerprint in Settings", ToastLength.Short).Show();
            }
            else
            {
                const int flags = 0; /* always zero (0) */

                // CryptoObjectHelper is described in the previous section.
                CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();

                // cancellationSignal can be used to manually stop the fingerprint scanner.
                var cancellationSignal = new Android.Support.V4.OS.CancellationSignal();


                // AuthenticationCallback is a base class that will be covered later on in this guide.
                //FingerprintManagerCompat.AuthenticationCallback authenticationCallback = new MyAuthCallbackSample(this);

                // Start the fingerprint scanner.
                fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(), flags, cancellationSignal, this, null);

                Toast.MakeText(Context, "Put your finger to scan", ToastLength.Short).Show();
            }

            return(tcs.Task);
        }
Пример #19
0
        public void fingerPrintDetection(Activity context)
        {
            // Using the Android Support Library v4
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(context);

            if (fingerprintManager.IsHardwareDetected)
            {
                if (fingerprintManager.HasEnrolledFingerprints)
                {
                    // The context is typically a reference to the current activity.
                    Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(context, Manifest.Permission.UseFingerprint);
                    if (permissionResult == Android.Content.PM.Permission.Granted)
                    {
                        // Permission granted - go ahead and start the fingerprint scanner.
                        CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
                        var cancellationSignal          = new Android.Support.V4.OS.CancellationSignal();

                        // AuthCallbacks is a C# class defined elsewhere in code.
                        FingerprintManagerCompat.AuthenticationCallback authenticationCallback = new SimpleAuthCallbacks(context);

                        // Here is where the CryptoObjectHelper builds the CryptoObject.
                        fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(), (int)FingerprintAuthenticationFlags.None, cancellationSignal, authenticationCallback, null);
                    }
                    else
                    {
                        // No permission. Go and ask for permissions and don't start the scanner. See
                        // http://developer.android.com/training/permissions/requesting.html
                    }
                }
                else
                {
                    //user has not enrolled for fingerprint
                }
            }
            else
            {
                //Device is not compatible for fingerprint scanning
            }
        }
Пример #20
0
        public void Authenticate(string userId, Action onSuccess, Action onFailure)
        {
            OnSuccess = onSuccess;
            OnFailure = onFailure;
            if (IsBiometricPromptEnabled)
            {
                newCancelSignal = new Android.OS.CancellationSignal();
                prompt          = new BiometricPrompt.Builder(CrossCurrentActivity.Current.Activity)
                                  .SetTitle("ManageGo")
                                  .SetSubtitle("Fingerprint Login")
                                  .SetDescription($"Place finger on the home button to log in as {userId}")
                                  .SetNegativeButton("CANCEL", CrossCurrentActivity.Current.Activity.MainExecutor,
                                                     new DialogListener(this)).Build();

                prompt.Authenticate(newCancelSignal, CrossCurrentActivity.Current.Activity.MainExecutor, new BiometricCallback(this));
            }
            else
            {
                cancellationSignal = new Android.Support.V4.OS.CancellationSignal();
                var callback = new SimpleAuthCallbacks(this);
                FingerprintManager.Authenticate(null, 0, cancellationSignal, callback, null);
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "FingerprintAuthorization" layout resource
            SetContentView(Resource.Layout.FingerprintAuthorization);

            sharedPreferences        = PreferenceManager.GetDefaultSharedPreferences(this);
            fingerprintManagerCompat = FingerprintManagerCompat.From(this);
            cancelationSignal        = new Android.Support.V4.OS.CancellationSignal();

            fingerprintStatusTextView = FindViewById <TextView>(Resource.Id.tvFingerprintStatusTextView);
            buttonAuthenticate        = FindViewById <Button>(Resource.Id.buttonFingerPrintAuthenticate);
            buttonReset = FindViewById <Button>(Resource.Id.buttonFingerPrintReset);
            FindViewById <ProgressBar>(Resource.Id.pbFingerprintAuthenticationProgressBar).Visibility = ViewStates.Invisible;

            buttonAuthenticate.Click += (sender, e) => {
                // Implementation
                FindViewById <ProgressBar>(Resource.Id.pbFingerprintAuthenticationProgressBar).Visibility = ViewStates.Visible;

                if (CanUseFingerprintBiometric())
                {
                    LogUserIn();
                }
                else
                {
                    FindViewById <ProgressBar>(Resource.Id.pbFingerprintAuthenticationProgressBar).Visibility = ViewStates.Invisible;
                    Toast.MakeText(this, "This device is not configured for Fingerprint Biometrics", ToastLength.Long).Show();
                }
            };

            buttonReset.Click += (sender, e) => {
                // Implementation
                FindViewById <ProgressBar>(Resource.Id.pbFingerprintAuthenticationProgressBar).Visibility = ViewStates.Invisible;
                fingerprintStatusTextView.Text = "You Must Authenticate";
            };
        }
        /// <summary>
        /// Starts the authentication.
        /// </summary>
        public void StartAuthentication()
        {
            // Stop any previous scan.
            StopAuthentication();

            if (!InternalIsFingerprintAvailable())
            {
                return;
            }

            try
            {
                mCancellationSignal = new CancellationSignal();
                _fingerprintManager.Authenticate(CryptoObjectBuilder.Build(),
                                                 (int)FingerprintAuthenticationFlags.None,
                                                 mCancellationSignal,
                                                 new AuthenticationCallbacks(this),
                                                 null);
            }
            catch (Exception ex)
            {
                _authenticationCallback.AuthenticationError(AuthenticationErrorCodes.Unexpected, ex.Message);
            }
        }
        public void Authenticate(byte[] secret, FingerprintSignOp operation)
        {
            const int flags = 0; /* Sempre zero */

            if (!IsReady())
            {
                throw new Exception(Resources.GetString(Resource.String.errFpNotRead));
            }

            // Estrae l'initialization vector
            byte[] iv = new byte[] { };
            if (operation == FingerprintSignOp.Decrypt)
            {
                string   data       = System.Text.Encoding.UTF8.GetString(secret);
                string[] base64Data = data.Split(new char[] { ';' });
                if (base64Data.Length < 2)
                {
                    throw new Exception("Invalid data");
                }
                secret = Convert.FromBase64String(base64Data[0]);
                iv     = Convert.FromBase64String(base64Data[1]);
            }

            // Oggetto per la verifica dell'integrità dell'impronta digitale
            CurrentOperation = operation;
            CryptoObjectHelper cryptoHelper = new CryptoObjectHelper(operation == FingerprintSignOp.Crypt ? CipherMode.EncryptMode : CipherMode.DecryptMode, iv);

            // Segnale per la cancellazione manuale della lettura dell'impronta
            FingerprintCancel = new Android.Support.V4.OS.CancellationSignal();

            // Oggetto per la gestione della callback di autenticazione
            FingerprintManagerCompat.AuthenticationCallback authenticationCallback = new FingerprintAuthCallback(this, secret);

            // Avvia lo scanner
            FingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(), flags, FingerprintCancel, authenticationCallback, null);
        }
        public override void OnResume()
        {
            base.OnResume();
            if (!ScanForFingerprintsInOnResume)
            {
                return;
            }

            UserCancelledScan = false;
            _cancellationSignal = new CancellationSignal();
            _fingerprintManager.Authenticate(CryptObjectHelper.BuildCryptoObject(),
                                             (int) FingerprintAuthenticationFlags.None, /* flags */
                                             _cancellationSignal,
                                             new SimpleAuthCallbacks(this),
                                             null);
        }
Пример #25
0
        public static async System.Threading.Tasks.Task Authenticate(DialogConfiguration dialogConfiguration)
        {
            //Android 10+ Q SdkInt 29+
            if ((int)Build.VERSION.SdkInt >= 29)
            {
                CancellationSignal BiometricCancellationSignal = new CancellationSignal();
                //Android 10
                BiometricCancellationSignal = new CancellationSignal();
                BiometricPrompt biometricPrompt;
                if (dialogConfiguration.IsUseAlternativeAuthentication)
                {
                    //Allow using PIN / Passcode as alternative, will disable crypto in authentication
                    biometricPrompt = new BiometricPrompt
                                      .Builder(Configuration.CurrentActivity)
                                      .SetTitle(dialogConfiguration.DialogTitle)
                                      .SetDescription(dialogConfiguration.DialogDescription)
                                      .SetDeviceCredentialAllowed(true)
                                      .Build();
                }
                else
                {
                    biometricPrompt = new BiometricPrompt
                                      .Builder(Configuration.CurrentActivity)
                                      .SetTitle(dialogConfiguration.DialogTitle)
                                      .SetDescription(dialogConfiguration.DialogDescription)
                                      .SetNegativeButton(dialogConfiguration.AlternativeActionMessage, Configuration.CurrentActivity.MainExecutor, new NegativeButtonOnClickListener(() =>
                    {
                        BiometricCancellationSignal.Cancel();
                        dialogConfiguration.AlternativeAction?.Invoke();
                    }))
                                      .Build();
                }
                BiometricPrompt.AuthenticationCallback authenticationCallback = new BiometricAuthenticationCallback();
                AuthenticationResult = null;
                AuthenticationResult = (arg) =>
                {
                    string result = arg;
                    if (arg == SystemMessages.Success)
                    {
                        BiometricCancellationSignal.Cancel();
                        dialogConfiguration.SuccessAction?.Invoke();
                    }
                    else if (arg == SystemMessages.Error)
                    {
                        BiometricCancellationSignal.Cancel();
                        dialogConfiguration.FailedAction?.Invoke();
                    }
                };
                if (dialogConfiguration.IsUseAlternativeAuthentication)
                {
                    //Secret key is not allowed to use when SetDeviceCredentialAllowed is true
                    biometricPrompt.Authenticate(BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                }
                else
                {
                    if (Configuration.IsUseSecretKey)
                    {
                        CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
                        biometricPrompt.Authenticate(cryptoHelper.BuildBiometricPromptCryptoObject(), BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                    }
                    else
                    {
                        biometricPrompt.Authenticate(BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                    }
                }
            }
            //Android 9+ P SdkInt 28
            else if ((int)Build.VERSION.SdkInt >= 28)
            {
                //Android 9
                try
                {
                    CancellationSignal BiometricCancellationSignal = new CancellationSignal();
                    BiometricPrompt    biometricPrompt;
                    biometricPrompt = new BiometricPrompt
                                      .Builder(Configuration.CurrentActivity)
                                      .SetTitle(dialogConfiguration.DialogTitle)
                                      .SetDescription(dialogConfiguration.DialogDescription)
                                      .SetNegativeButton(dialogConfiguration.AlternativeActionMessage, Configuration.CurrentActivity.MainExecutor, new NegativeButtonOnClickListener(() =>
                    {
                        BiometricCancellationSignal.Cancel();
                        dialogConfiguration.AlternativeAction?.Invoke();
                    }))
                                      .Build();

                    BiometricCancellationSignal = new CancellationSignal();

                    BiometricPrompt.AuthenticationCallback authenticationCallback = new BiometricAuthenticationCallback();
                    AuthenticationResult = null;
                    AuthenticationResult = (arg) =>
                    {
                        string result = arg;
                        if (arg == SystemMessages.Success)
                        {
                            BiometricCancellationSignal.Cancel();
                            dialogConfiguration.SuccessAction?.Invoke();
                        }
                        else if (arg == SystemMessages.Error)
                        {
                            BiometricCancellationSignal.Cancel();
                            dialogConfiguration.FailedAction?.Invoke();
                        }
                    };
                    if (Configuration.IsUseSecretKey)
                    {
                        CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
                        biometricPrompt.Authenticate(cryptoHelper.BuildBiometricPromptCryptoObject(), BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                    }
                    else
                    {
                        biometricPrompt.Authenticate(BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                    }
                }
                catch (Exception ex)
                {
                    Configuration.CurrentActivity.RunOnUiThread(() =>
                    {
                        Toast.MakeText(Configuration.CurrentActivity, $"Throw exception : {ex.Message}", ToastLength.Long).Show();
                    });
                }
            }
            //Android 6+ to 8.x SdkInt 23
            else if ((int)Build.VERSION.SdkInt >= 23)
            {
                //Android 6+ to 8.x
                FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(Configuration.CurrentActivity);
                const int          flags        = 0; /* always zero (0) */
                CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
                // Using the Support Library classes for maximum reach
                FingerprintManagerCompat fingerPrintManager = FingerprintManagerCompat.From(Configuration.CurrentActivity);
                // AuthCallbacks is a C# class defined elsewhere in code.

                Android.Support.V4.OS.CancellationSignal        FingerprintCancellationSignal = new Android.Support.V4.OS.CancellationSignal();
                FingerprintManagerCompat.AuthenticationCallback authenticationCallback        = new AuthenticationCallBack();

                Android.Support.V4.App.FragmentTransaction transcation = ((FragmentActivity)Configuration.CurrentActivity).SupportFragmentManager.BeginTransaction();
                FingerprintDialog fingerprintDialog = new FingerprintDialog(dialogConfiguration, authenticationCallback, FingerprintCancellationSignal);
                fingerprintDialog.Show(transcation, "Dialog Fragment");

                AuthenticationResult = null;
                AuthenticationResult = (arg) =>
                {
                    string result = arg;
                    if (arg == SystemMessages.Success)
                    {
                        FingerprintCancellationSignal.Cancel();
                        dialogConfiguration.SuccessAction?.Invoke();
                    }
                    else if (arg == SystemMessages.Error)
                    {
                        FingerprintCancellationSignal.Cancel();
                        dialogConfiguration.FailedAction?.Invoke();
                    }
                };
                try
                {
                    fingerprintManager.Authenticate(cryptoHelper.BuildFingerprintManagerCompatCryptoObject(), flags, FingerprintCancellationSignal, authenticationCallback, null);
                }
                catch (Exception ex)
                {
                    Toast.MakeText(Configuration.CurrentActivity, $"Throw exception : {ex.Message}", ToastLength.Long);
                }
            }
        }
Пример #26
0
 public Fingerprint()
 {
     m_ready            = false;
     cancellationSignal = null;
     m_mode             = CipherMode.EncryptMode;
 }
 void StopListeningForFingerprints(bool butStartListeningAgainInOnResume = false)
 {
     if (_cancellationSignal != null)
     {
         _cancellationSignal.Cancel();
         _cancellationSignal = null;
         Log.Debug(TAG, "StopListeningForFingerprints: _cancellationSignal.Cancel();");
     }
     ScanForFingerprintsInOnResume = butStartListeningAgainInOnResume;
 }