I have app which uses Fingerprint and 4 digit pin (which can be set by user in application settings, this is not system pin/pattern/password) authorization.
With Fingerprint everything is fine, I have problem with pin.
What I'm trying to do is:
- Let user set pin from application settings
- Generate Keypair in keystore for some alias protected by entered pin (so that private key can not be accessed without this pin)
- Send public key to server for future signature verification
- Get user token from server and store it in local storage
Then during Authorization:
- Request user to enter the pin
- Retrieve private key by entered pin
- Retrieve token from local storage
- Sign token with private key from step 6
- Send it to server with signed data
- Verify signature on server and if it is valid, open session for user.
My question is: How can I generate KeyPair protected by pin entered by user
P.S. For fingerprint this logic is handled by:
KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_SIGN).setUserAuthenticationRequired(true)
I will suggest try to use this post Use the Android KeyStore to securely store arbitrary strings post.
This post have covered point as
Generate, securely store, and retrieve encryption keys on the device.
Encrypt arbitrary data and save it on the device.
Access and decrypt the data for subsequent use.
I hope it will help.
来源:https://stackoverflow.com/questions/40548551/how-to-generate-keypair-in-android-keystore-protected-by-custom-password