Tôi có mật khẩu được mã hóa được lưu trữ trong Android KeyStore.UserNotAuthenticatedException trong FingerprintManager.authenticate()
Tôi muốn giải mã mật khẩu đó bằng cách xác thực người dùng bằng API vân tay.
Theo như tôi hiểu, tôi phải gọi phương thức FingerprintManager.authenticate(CryptoObject cryptoObject)
để bắt đầu nghe kết quả vân tay. Tham số CryptoObject được tạo ra như thế này:
public static Cipher getDecryptionCipher(Context context) throws KeyStoreException {
try {
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
SecretKey secretKey = getKeyFromKeyStore();
final IvParameterSpec ivParameterSpec = getIvParameterSpec(context);
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec);
return cipher;
} catch (NoSuchAlgorithmException | NoSuchPaddingException | IOException | UnrecoverableKeyException | CertificateException | InvalidAlgorithmParameterException | InvalidKeyException e) {
e.printStackTrace();
}
return null;
}
Cipher cipher = FingerprintCryptoHelper.getDecryptionCipher(getContext());
FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
fingerprintManager.authenticate(cryptoObject, ...);
Phương pháp getDecryptionCipher()
hoạt động chính xác cho đến khi cipher.init()
gọi. Trong cuộc gọi này, tôi nhận được UserNotAuthenticatedException
vì người dùng không được xác thực cho khóa bí mật này. Điều đó có ý nghĩa bằng cách nào đó. Nhưng không phải là thế này một vòng, không thể thực hiện:
- Để xác thực người dùng, tôi muốn sử dụng anh/vân tay cô
- Để nghe cho/vân tay của mình, tôi cần phải init Mật mã, đổi lại cần một người dùng được xác thực
Có gì sai ở đây ??
EDIT:
tôi làm việc với các giả lập (Nexus 4, API 23).
Đây là mã tôi sử dụng để tạo khóa.
private SecretKey createKey() {
try {
KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEY_STORE);
keyGenerator.init(new KeyGenParameterSpec.Builder(
KEY_NAME,
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT
)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setUserAuthenticationRequired(true)
.setUserAuthenticationValidityDurationSeconds(AUTHENTICATION_DURATION_SECONDS)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
.build());
return keyGenerator.generateKey();
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException e) {
throw new RuntimeException("Failed to create a symmetric key", e);
}
}
Bạn đang thử nghiệm thiết bị nào? Bạn đã tạo khóa như thế nào? – Michael
Và bạn đã đăng ký ít nhất một dấu vân tay trong trình mô phỏng? – Michael
@Michael Nó được thử nghiệm trên nhiều thiết bị khác nhau, từ thiết bị Nexus trên một số Samsung và HTC One Mini. Và có, tôi cũng đã thử nghiệm nó trên trình mô phỏng. – muetzenflo