Android指纹检测新手指添加

时间:2017-06-13 08:05:19

标签: android detect fingerprint biometrics

如何检测用户在我的应用程序中验证手指后是否将新指纹添加到Android设置?

即。 iOS有一些名为(evaluatePolicyDomainState)的东西来检测指纹目录中的变化Android中的替代方案是什么?

出于安全原因,这需要在这种情况下提示密码

4 个答案:

答案 0 :(得分:7)

来自setUserAuthenticationRequired的文档:

  

一旦禁用安全锁定屏幕(重新配置为无,刷卡或其他未对用户进行身份验证的模式)或强制重置安全锁定屏幕(例如,由设备管理员),密钥将变为不可逆转无效。此外,如果密钥要求在每次使用密钥时都进行用户身份验证,则一旦注册了新指纹,或者一旦不再注册指纹,它也会无可挽回地失效,除非setInvalidatedByBiometricEnrollment(boolean)用于在注册后允许有效性。尝试使用此类密钥初始化加密操作将导致KeyPermanentlyInvalidatedException。

因此,要检查自创建指纹相关密钥后是否已注册任何新指纹,只需使用该密钥创建密码并尝试init该密码。如果已注册任何新指纹,则init来电应触发KeyPermanentlyInvalidatedException

答案 1 :(得分:2)

我可以用整数获取所有手指ID。

private void getFingerprintInfo(Context context) 
{
    try {
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        Method method = FingerprintManager.class.getDeclaredMethod("getEnrolledFingerprints");
        Object obj = method.invoke(fingerprintManager);

        if (obj != null) {
            Class<?> clazz = Class.forName("android.hardware.fingerprint.Fingerprint");
            Method getFingerId = clazz.getDeclaredMethod("getFingerId");

            for (int i = 0; i < ((List) obj).size(); i++)
            {
                Object item = ((List) obj).get(i);
                if(item != null)
                {
                    System.out.println("fkie4. fingerId: " + getFingerId.invoke(item));
                }
            }
        }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
        e.printStackTrace();
    }
}

请参考以下内容:https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/fingerprint/Fingerprint.java

有一个公共方法getFingerId(),但是我们无法调用它,因为它具有“ @UnsupportedAppUsage”。

所以您需要使用反射来调用该方法。在获得指纹ID列表之后,您可以对其进行加密并存储在sharedPreference中。

手指ID是设置中存储的指纹的ID

获取所有手指ID后,您可以确定用户是否添加/删除了指纹。

无需依靠KeyPermanentlyInvalidatedException。它不会在Android 8.0中抛出

祝你好运!!! ...

不相信Google做得这么差

答案 2 :(得分:0)

/**
 * 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();
}

答案 3 :(得分:-1)

您无法从应用中添加新指纹。

在您的应用程序中,您只能访问Auth Fingerprint Method,该方法通过keyStore检查已注册的指纹。