Error after Fingerprint touched on Samsung phones: android.security.KeyStoreException: Key user not authenticated

后端 未结 9 1191
醉酒成梦
醉酒成梦 2020-12-14 19:48

My app uses Android 6.0 Fingerprint API to protect AES key in the Android KeyStore. The stored key can be used only when user is authenticated by fingerprint sensor because

9条回答
  •  情深已故
    2020-12-14 20:08

    I also had this issue when using RSA and could solve it by creating a copy of the public key as soon as i want to encrypt some data.

    // create a copy of the public key -> workaround for android.security.KeyStoreException: Key user not authenticated
    val publicKey = KeyFactory
        .getInstance("RSA")
        .generatePublic(X509EncodedKeySpec(keyPair.public.encoded))
    
    // encrypt with the public key
    val cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding")
    cipher.init(Cipher.ENCRYPT_MODE, publicKey)
    val encryptedData = cipher.doFinal(data)
    

提交回复
热议问题