-1

アプリに指紋認証を使用しています。API 23以下もサポートしたい。そのために、FingerprintManagerCompatを使用しています。Pre-Android API 23 でKeyChiper の開始を生成する方法がわかりません。

以下のコードは API 23 に使用されます - キーの生成

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 に使用されます - Chiper の開始

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);
    }
}

FingerprintManagerCompatにアクセスするために Pre API 23 でこれら 2 つのことを開始する方法がわかりません。この問題の解決を手伝ってください。

4

2 に答える 2

0

いいえ。API 23 (Marshmallow 6.0) 未満では、キーと暗号を生成できません。

一部の android デバイスには API 21 未満の指紋センサーがありますが、android は API 23 以降のみをサポートしています。指紋認証には自社の sdk を使用する必要があります。

このリンクを参照できます。指紋認証のサンプル プロジェクトはこちら

于 2016-11-30T09:39:13.317 に答える