private void generateSecretKey() { KeyGenParameterSpec keyGenParameterSpec = new KeyGenParameterSpec.Builder( "MySecretKey", KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT) .setBlockModes(KeyProperties.BLOCK_MODE_CBC) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7) // GOOD: Secure parameters are used to generate a key for biometric authentication. .setUserAuthenticationRequired(true) .setInvalidatedByBiometricEnrollment(true) .setUserAuthenticationParamters(0, KeyProperties.AUTH_BIOMETRIC_STRONG) .build(); KeyGenerator keyGenerator = KeyGenerator.getInstance( KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore"); keyGenerator.init(keyGenParameterSpec); keyGenerator.generateKey(); }