builder.setInvalidatedByBiometricEnrollment(invalidatedByBiometricEnrollment);
/** * Generate NIST P-256 EC Key pair for signing and verification * * @param keyName * @param invalidatedByBiometricEnrollment * @return * @throws Exception */ @TargetApi(Build.VERSION_CODES.P) private KeyPair generateKeyPair(String keyName, boolean invalidatedByBiometricEnrollment) throws Exception { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore"); KeyGenParameterSpec.Builder builder = new KeyGenParameterSpec.Builder(keyName, KeyProperties.PURPOSE_SIGN) .setAlgorithmParameterSpec(new ECGenParameterSpec("secp256r1")) .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA384, KeyProperties.DIGEST_SHA512) // Require the user to authenticate with a biometric to authorize every use of the key .setUserAuthenticationRequired(true) .setInvalidatedByBiometricEnrollment(invalidatedByBiometricEnrollment); keyPairGenerator.initialize(builder.build()); return keyPairGenerator.generateKeyPair(); }
/** * Generate NIST P-256 EC Key pair for signing and verification * @param keyName * @param invalidatedByBiometricEnrollment * @return * @throws Exception */ private KeyPair generateKeyPair(String keyName, boolean invalidatedByBiometricEnrollment) throws Exception { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore"); KeyGenParameterSpec.Builder builder = new KeyGenParameterSpec.Builder(keyName, KeyProperties.PURPOSE_SIGN) .setAlgorithmParameterSpec(new ECGenParameterSpec("secp256r1")) .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA384, KeyProperties.DIGEST_SHA512) // Require the user to authenticate with a biometric to authorize every use of the key .setUserAuthenticationRequired(true) .setInvalidatedByBiometricEnrollment(invalidatedByBiometricEnrollment); keyPairGenerator.initialize(builder.build()); return keyPairGenerator.generateKeyPair(); }