Search in sources :

Example 1 with SwirlView

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);
}
Also used : FingerprintManagerCompat(androidx.core.hardware.fingerprint.FingerprintManagerCompat) SwirlView(com.mattprecious.swirl.SwirlView) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) KeyGenerator(javax.crypto.KeyGenerator) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) KeyGenParameterSpec(android.security.keystore.KeyGenParameterSpec) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) KeyStore(java.security.KeyStore) SecretKey(javax.crypto.SecretKey) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) FrameLayout(android.widget.FrameLayout) NoSuchProviderException(java.security.NoSuchProviderException) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

KeyGenParameterSpec (android.security.keystore.KeyGenParameterSpec)1 FrameLayout (android.widget.FrameLayout)1 RequiresApi (androidx.annotation.RequiresApi)1 ContextThemeWrapper (androidx.appcompat.view.ContextThemeWrapper)1 FingerprintManagerCompat (androidx.core.hardware.fingerprint.FingerprintManagerCompat)1 SwirlView (com.mattprecious.swirl.SwirlView)1 IOException (java.io.IOException)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 BadPaddingException (javax.crypto.BadPaddingException)1 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)1 KeyGenerator (javax.crypto.KeyGenerator)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1 SecretKey (javax.crypto.SecretKey)1