我尝试使用react native biometrics,但是在创建并存储了公共密钥(作为下面的示例代码中的状态)之后,它再也不会与之后用同一根手指生成的签名匹配。如何验证指纹?
代码:
registerFingerPrint = () => {
Biometrics.isSensorAvailable()
.then((biometryType) => {
if (biometryType === Biometrics.TouchID) {
Biometrics.createKeys('Confirm fingerprint')
.then((publicKey) => {
console.log("create", publicKey)
this.setState({
create: publicKey
})
})
}
})
}
fingerPrintCheck = () => {
Biometrics.createSignature('Sign in', payload)
.then((signature) => {
if (this.state.create === signature){
console.log("success");
}else {
console.log('failure'); //always returns failure here
}
})
}
render() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={()=> this.registerFingerPrint()}>
<Text style={{ marginBottom: 10}}>
Register
</Text>
</TouchableHighlight>
<TouchableHighlight onPress={()=> this.fingerPrintCheck()}>
<Text>
Authenticate with Biometrics
</Text>
</TouchableHighlight>
</View>
);
}
}
答案 0 :(得分:0)
let epochTimeSeconds = Math.round((new Date()).getTime() / 1000).toString()
let payload = epochTimeSeconds +'some message' ;
Biometrics.createSignature('Sign in Test', payload)
.then((signature) => {
console.log(payload+" signature "+signature)
verifySignatureWithServer(signature, payload)
})
您需要使用生成的签名和有效载荷组合在服务器端检查验证。
转到此站点,然后粘贴生成的公共密钥,签名,有效负载并进行验证。
https://8gwifi.org/RSAFunctionality?rsasignverifyfunctions=rsasignverifyfunctions&keysize=512