private void OnClickFingerAuthWithCrpObj(object sender, EventArgs e) { string Tag = "FingerAuthWithCrpObj"; int errorCode = fingerprintManager.CanAuth(); if (errorCode != 0) { log.Info(Tag, "Can not authenticate. errorCode=" + errorCode); return; } // Construct CryptoObject. Cipher cipher = new HwBioAuthnCipherFactory("hw_test_fingerprint", true).GetCipher(); if (cipher == null) { log.Info(Tag, "Failed to create Cipher object."); return; } CryptoObject crypto = new CryptoObject(cipher); log.Info(Tag, "Start fingerprint authentication with CryptoObject.\nAuthenticating......\n"); fingerprintManager.Auth(crypto); }
private void OnClickFaceAuthWithCrpObj(object sender, EventArgs e) { string Tag = "FaceAuthWithCrpObj"; Android.Content.PM.Permission permissionCheck = Android.Content.PM.Permission.Granted; if (Build.VERSION.SdkInt >= BuildVersionCodes.M) { permissionCheck = CheckSelfPermission(Manifest.Permission.Camera); } if (permissionCheck != Android.Content.PM.Permission.Granted) { log.Info(Tag, "The camera permission is not enabled. Please enable it."); // request camera permissions if (Build.VERSION.SdkInt >= BuildVersionCodes.M) { RequestPermissions(new string[] { Manifest.Permission.Camera }, 1); } return; } BioAuthnCallback callback = new FidoBioAuthnCallback(); // Cancellation Signal CancellationSignal cancellationSignal = new CancellationSignal(); FaceManager faceManager = new FaceManager(this); Log.Info("HasEnrolledTemplates", faceManager.HasEnrolledTemplates.ToString()); Log.Info("IsHardwareDetected", faceManager.IsHardwareDetected.ToString()); Log.Info("CanAuth", faceManager.CanAuth().ToString()); log.Info(Tag, $"IsHardwareDetected:{faceManager.IsHardwareDetected}"); // Checks whether 3D facial authentication can be used. int errorCode = faceManager.CanAuth(); if (errorCode != 0) { log.Info(Tag, "Can not authenticate. errorCode=" + errorCode); return; } // flags int flags = 0; // Authentication messsage handler. Handler handler = null; // Recommended CryptoObject to be set to null. KeyStore is not associated with face authentication in current // version. KeyGenParameterSpec.Builder.SetUserAuthenticationRequired() must be set false in this scenario. CryptoObject crypto = null; log.Info(Tag, "Start face authentication.\nAuthenticating......\n"); faceManager.Auth(crypto, cancellationSignal, flags, callback, handler); }
/// <summary> /// Shows the fingerprint prompt with CryptoObject. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnClickFingerAuthWithCrpObj(object sender, EventArgs e) { string Tag = "FingerAuthWithCrpObj"; BioAuthnManager bioAuthnManager = new BioAuthnManager(this); int errorCode = bioAuthnManager.CanAuth(); if (errorCode != 0) { log.Info(Tag, "Can not authenticate. errorCode=" + errorCode); return; } // build prompt info BioAuthnPrompt.PromptInfo.Builder builder = new BioAuthnPrompt.PromptInfo.Builder().SetTitle("This is the title.") .SetSubtitle("This is the subtitle.") .SetDescription("This is the description."); // The user will first be prompted to authenticate with biometrics, but also given the option to // authenticate with their device PIN, pattern, or password. SetNegativeButtonText(string) should // not be set if this is set to true. // builder.SetDeviceCredentialAllowed(true); // Set the text for the negative button. SetDeviceCredentialAllowed(true) should not be set if this // button text is set. builder.SetNegativeButtonText("This is the 'Cancel' button."); BioAuthnPrompt.PromptInfo info = builder.Build(); // Construct CryptoObject. Cipher cipher = new HwBioAuthnCipherFactory("hw_test_fingerprint", true).GetCipher(); if (cipher == null) { log.Info(Tag, "Failed to create Cipher object."); return; } CryptoObject crypto = new CryptoObject(cipher); log.Info(Tag, "Start fingerprint authentication with CryptoObject.\nAuthenticating......\n"); // When user CryptoObject, BiometricPrompt.PromptInfo.Builder.SetDeviceCredentialAllowed(true) is not allow. // Call BiometricPrompt.Authenticate(BiometricPrompt.PromptInfo info) if // BiometricPrompt.PromptInfo.Builder.SetDeviceCredentialAllowed(true) is set to true. Log.Info("CanAuth", bioAuthnManager.CanAuth().ToString()); bioAuthnPrompt.Auth(info, crypto); Thread.Sleep(10000); bioAuthnPrompt.CancelAuth(); }