0

Am Using Fingerprint Authentication for App. Want to Support for below API 23 also. For that am Using FingerprintManagerCompat. I don't know how to Generate Key and Chiper initiation in Pre-Android API 23.

Below Code am Used for API 23 - Generate Key

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

Below Code am Used for API 23 - Chiper initiation

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

I don't know how initiate these two things in Pre API 23 to access FingerprintManagerCompat, Help me to solve this issue.

Yugesh
  • 4,030
  • 9
  • 57
  • 97

2 Answers2

1

FingerprintManager is not available in pre-marshmallow devices. They have added this API in Marshamallow which is specified here

chetan
  • 681
  • 4
  • 21
1

No.You can't Generate Key and cipher below API 23(Marshmallow 6.0).

Some android device have fingerprint sensor below API 21 but android only supports for API 23 and above.You have to use their sdk for fingerprint authentication.Samsung provide their own sdk for fingerprint authentication i.e Pass Sdk.

You can see this link.Sample project for Finger Print Authentication here

Sagar Gangawane
  • 1,985
  • 1
  • 12
  • 22