Когда я регистрирую первый и единственный отпечаток и генерирую KeyPair
, PrivateKey
становится недействительным, когда я использую его во второй раз. Это происходит только один раз. Я единственный, у кого есть эта проблема? Что-то не так с моим кодом?
Я не могу использовать какой-либо другой ключ, поскольку я использую PrivateKey
для подписи данных.
Шаги:
- Вытрите все отпечатки пальцев
- Зарегистрировать один отпечаток пальца
- Сгенерируйте
KeyPair
и используйтеFingerprintManager :: authenticate
- Во время следующего использования
FingerprintManager :: authenticate PrivateKey
становится недействительным. Это происходит только в первый раз
Ниже кода, в котором я создаю KeyPair
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keystore.load(null);
KeyPairGenerator generator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore");
generator.initialize(new KeyGenParameterSpec.Builder("key_name", KeyProperties.PURPOSE_SIGN)
.setDigests(digest) // I have defined digest before
.setSignaturePaddings(paddings) // I have defined paddings before
.setUserAuthenticationRequired(true)
.build());
generator.generateKeyPair();
И вот код, в котором я вызываю аутентификацию отпечатка пальца для подписи данных:
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
Signature signature = Signature.getInstance("signing_algorithm");
PrivateKey privateKey = (PrivateKey) keyStore.getKey("key_name", null);
signature.initSign(privateKey); // Here I get KeyPermanentlyInvalidatedException
CryptoObject crypto = new CryptoObject(signature);
FingerprintManager fingerprintManager = context.getSystemService(FingerprintManager.class);
CancellationSignal cancellationSignal = new CancellationSignal();
AuthenticationCallback authenticationCallback = new AuthenticationCallback() {
...
};
fingerprintManager.authenticate(crypto, cancelationSignal, 0, authenticationCallback, null);