我正在使用生物识别技术对我的应用程序中的用户进行身份验证,
他们是颤振中检测手机中是否添加了新手指的方法吗?
这取决于平台以及您想要如何执行此操作。
在 Android 上,当您创建密钥时,您可以指定如果使用
KeyGenParameterSpec.Builder
的 setInvalidatedByBiometricEnrollment
功能注册了其他指纹,则该密钥将失效。但是,有一个警告 - 它仅适用于需要主动身份验证的密钥,并且发现密钥已失效的唯一方法是尝试对其进行身份验证...如果是这样,则会抛出 KeyPermanentlyInvalidatedException
这种情况,但如果它仍然有效,可能会打开身份验证对话框,这可能不是您想要的用户体验。
在 iOS 上,它更简单一些,因为您可以检查域状态
let context = LAContext()
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil {
if let newDomainState = context.evaluatedPolicyDomainState {
if newDomainState.base64EncodedString() != oldDomainStateString {
// doesn't match so have to update oldDomainStateString (wherever that is saved)
// and do whatever else.
} else {
// domains still match, fingerprint still the same.
}
} else {
// can't get the policy for some reason. Hopefully shouldn't happen
// since we're checking canEvaluatePolicy
}
}
但是,还有另一个问题 - 这些 API 都不是通过我所知道的任何插件直接公开的,因此您必须自己编写本机代码。老实说,这可能不是最糟糕的事情,因为你应该对这些东西有很好的理解,或者很好地阅读你使用的任何第三方库,但这确实意味着你必须有很好地理解 flutter 的平台渠道,以及 iOS/swift 和 Android/kotlin 代码和安全 API,以便能够实现它。