Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate key using KeyGenerator for FingerPrint API in Android

I am trying to implement the FingerPrint API for my application. I am following the Google's Fingerprint Dialog sample for this purpose.

It works fine if compileSdkVersion=23 and minSdkVersion=23 but my application's compileSdkVersion is 21 and minSdkVersion is 14. For this purpose, I am using FingerprintManagerCompat instead of FingerprintManager which works fine but the issue is with the Key generation.

android.security.keystore.KeyGenParameterSpec;
android.security.keystore.KeyPermanentlyInvalidatedException;
android.security.keystore.KeyProperties;

Keystore package and its classes are not available to generate the key, all the supported algorithms for the key generation available in 18+ API versions, anybody can guide me how to generate the key to support lower versions, please?

like image 654
Gulfam Avatar asked Feb 11 '16 14:02

Gulfam


1 Answers

Looking at FingerprintManagerCompat javadoc:

A class that coordinates access to the fingerprint hardware.

On platforms before M, this class behaves as there would be no fingerprint hardware available.

Looking at the source code:

final int version = Build.VERSION.SDK_INT;
if (version >= 23) {
   // a working implementation
   IMPL = new Api23FingerprintManagerCompatImpl();
} else {
   // an empty stub
   IMPL = new LegacyFingerprintManagerCompatImpl();
}

If your device is below API VERSION 23, the LegacyFingerprintManagerCompatImpl is used, and this is only a STUB. For example:

@Override
public boolean hasEnrolledFingerprints(Context context) {
   return false;
}
@Override
public boolean isHardwareDetected(Context context) {
   return false;
}

You cannot use such feature in older device. Those API (some from android.security.keystore) are available only on Android M

like image 130
Sarbyn Avatar answered Sep 29 '22 17:09

Sarbyn