use of com.mattprecious.swirl.SwirlView in project MTweaks-KernelAdiutorMOD by morogoku.
the class SecurityActivity method loadFingerprint.
@RequiresApi(api = Build.VERSION_CODES.M)
private void loadFingerprint() {
try {
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
mCipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
keyStore.load(null);
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();
SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null);
mCipher.init(Cipher.ENCRYPT_MODE, key);
} catch (KeyStoreException | NoSuchProviderException | NoSuchAlgorithmException | NoSuchPaddingException | UnrecoverableKeyException | InvalidKeyException | CertificateException | InvalidAlgorithmParameterException | IOException e) {
return;
}
mCryptoObject = new FingerprintManagerCompat.CryptoObject(mCipher);
FrameLayout fingerprintParent = findViewById(R.id.fingerprint_parent);
final SwirlView swirlView = new SwirlView(new ContextThemeWrapper(this, R.style.Swirl));
swirlView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
fingerprintParent.addView(swirlView);
fingerprintParent.setVisibility(View.VISIBLE);
mFingerprintUiHelper = new FingerprintUiHelper.FingerprintUiHelperBuilder(mFingerprintManagerCompat).build(swirlView, new FingerprintUiHelper.Callback() {
@Override
public void onAuthenticated() {
try {
mCipher.doFinal(SECRET_MESSAGE.getBytes());
mPasswordWrong.setVisibility(View.GONE);
setResult(1);
finish();
} catch (IllegalBlockSizeException | BadPaddingException e) {
e.printStackTrace();
swirlView.setState(SwirlView.State.ERROR);
}
}
@Override
public void onError() {
}
});
mFingerprintUiHelper.startListening(mCryptoObject);
}
Aggregations