2016-11-19 45 views
-1

上午使用指紋認證的應用程序。還希望支持API 23以下。對於那是使用FingerprintManagerCompat。我不知道該怎麼預Android的API 23如何在Android API 23下生成Key和Chiper啓動?

下面的代碼我用於23 API生成密鑰Chiper啓動 - 生成密鑰

protected void generateKey() { 
    try { 
     keyStore = KeyStore.getInstance("AndroidKeyStore"); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    try { 
     keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore"); 
    } catch (NoSuchAlgorithmException | 
      NoSuchProviderException e) { 
     throw new RuntimeException("Failed to get KeyGenerator instance", e); 
    } 

    try { 
     keyStore.load(null); 
     keyGenerator.init(new 
       KeyGenParameterSpec.Builder(KEY_NAME, 
       KeyProperties.PURPOSE_ENCRYPT | 
         KeyProperties.PURPOSE_DECRYPT) 
       .setBlockModes(KeyProperties.BLOCK_MODE_CBC) 
       .setUserAuthenticationRequired(true) 
       .setEncryptionPaddings(
         KeyProperties.ENCRYPTION_PADDING_PKCS7) 
       .build()); 
     keyGenerator.generateKey(); 
    } catch (NoSuchAlgorithmException | 
      InvalidAlgorithmParameterException 
      | CertificateException | IOException e) { 
     throw new RuntimeException(e); 
    } 
} 

下面的代碼是用於API 23 - 引發赤字

public boolean cipherInit() { 
    try { 
     cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7); 
    } catch (NoSuchAlgorithmException | 
      NoSuchPaddingException e) { 
     throw new RuntimeException("Failed to get Cipher", e); 
    } 

    try { 
     keyStore.load(null); 
     SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null); 
     cipher.init(Cipher.ENCRYPT_MODE, key); 
     return true; 
    } catch (KeyStoreException | CertificateException 
      | UnrecoverableKeyException | IOException 
      | NoSuchAlgorithmException | InvalidKeyException e) { 
     throw new RuntimeException("Failed to init Cipher", e); 
    } 
} 

我不知道如何啓動這兩件事在Pre API 23中訪問FingerprintManagerCompat,幫我解決這個問題。

回答

0

FingerprintManager不適用於棉花糖前裝置。他們在Marshamallow中添加了這個API,這是指定的here

+0

指紋傳感器可用。 – Yugesh

0

不可以。您不能在API 23(Marshmallow 6.0)下生成密鑰和密碼。

一些Android設備有以下API 21指紋傳感器但是Android僅支持API 23 above.You必須要用自己的SDK指紋authentication.Samsung提供指紋認證即通SDK自己的SDK。

你可以看到這個link。樣品項目指紋驗證與API 21有些手機here

相關問題