Comments (2)
Facing the same issue with same device.
Try replacing the below class in library and try again.
import android.annotation.TargetApi;
import android.content.Context;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.CancellationSignal;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyPermanentlyInvalidatedException;
import android.security.keystore.KeyProperties;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.UUID;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import static android.content.Context.FINGERPRINT_SERVICE;
@TargetApi(Build.VERSION_CODES.M)
public class BiometricManagerV23 {
private static final String KEY_NAME = UUID.randomUUID().toString();
private Cipher cipher;
private KeyStore keyStore;
private KeyGenerator keyGenerator;
private FingerprintManager.CryptoObject cryptoObject;
protected Context context;
protected String title;
protected String subtitle;
protected String description;
protected String negativeButtonText;
private BiometricDialogV23 biometricDialogV23;
protected CancellationSignal mCancellationSignalV23 = new CancellationSignal();
public void displayBiometricPromptV23(final BiometricCallback biometricCallback) {
generateKey();
if (initCipher()) {
FingerprintManager fingerprintManager;
fingerprintManager = (FingerprintManager) context.getSystemService(FINGERPRINT_SERVICE);
cryptoObject = new FingerprintManager.CryptoObject(cipher);
fingerprintManager.authenticate(cryptoObject, mCancellationSignalV23, 0 /* flags */, new FingerprintManager.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
updateStatus(String.valueOf(errString));
biometricCallback.onAuthenticationError(errorCode, errString);
}
@Override
public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
super.onAuthenticationHelp(helpCode, helpString);
updateStatus(String.valueOf(helpString));
biometricCallback.onAuthenticationHelp(helpCode, helpString);
}
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
dismissDialog();
biometricCallback.onAuthenticationSuccessful();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
updateStatus(context.getString(R.string.biometric_failed));
biometricCallback.onAuthenticationFailed();
}
}, null);
displayBiometricDialog(biometricCallback);
}
}
private void displayBiometricDialog(final BiometricCallback biometricCallback) {
biometricDialogV23 = new BiometricDialogV23(context, biometricCallback);
biometricDialogV23.setTitle(title);
biometricDialogV23.setSubtitle(subtitle);
biometricDialogV23.setDescription(description);
biometricDialogV23.setButtonText(negativeButtonText);
biometricDialogV23.show();
}
private void dismissDialog() {
if (biometricDialogV23 != null) {
biometricDialogV23.dismiss();
}
}
private void updateStatus(String status) {
if (biometricDialogV23 != null) {
biometricDialogV23.updateStatus(status);
}
}
private void generateKey() {
try {
keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
keyGenerator.init(new
KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setUserAuthenticationRequired(true)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
.build());
keyGenerator.generateKey();
} catch (KeyStoreException
| NoSuchAlgorithmException
| NoSuchProviderException
| InvalidAlgorithmParameterException
| CertificateException
| IOException exc) {
exc.printStackTrace();
}
}
private boolean initCipher() {
try {
cipher = Cipher.getInstance(
KeyProperties.KEY_ALGORITHM_AES + "/"
+ KeyProperties.BLOCK_MODE_CBC + "/"
+ KeyProperties.ENCRYPTION_PADDING_PKCS7);
} catch (NoSuchAlgorithmException |
NoSuchPaddingException e) {
throw new RuntimeException("Failed to get Cipher", e);
}
try {
keyStore.load(null);
SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME,
null);
cipher.init(Cipher.ENCRYPT_MODE, key);
return true;
} catch (KeyPermanentlyInvalidatedException e) {
return false;
} catch (KeyStoreException | CertificateException
| UnrecoverableKeyException | IOException
| NoSuchAlgorithmException | InvalidKeyException e) {
throw new RuntimeException("Failed to init Cipher", e);
}
}
}
from biometric-auth-sample.
@JeffJJJ Did this help?
from biometric-auth-sample.
Related Issues (18)
- Add License HOT 3
- Not Showing Bio-Metric Dialog on Android P devices HOT 9
- Crash in Android Version 7 API 24 HOT 4
- Disable Facial Authentication HOT 2
- Unable to Import
- Support for 3rd party
- Display fingerprint dialog
- For some device the init Cipher doesn't work (API 23)
- Publish to Jitpack HOT 1
- Crash HOT 1
- How to make the biometric dialog full screen?
- attr/bottomSheetStyle Not Found
- Localization issue in v23
- Style not found HOT 3
- Biometric Builder not showing. HOT 1
- Enable to prevent device back button on Android 9 and above HOT 1
- [How to] Canceling fingerprint scanning ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from biometric-auth-sample.