The Benefits of Forest Bathing

Thankfully forest bathing isn’t quite as it sounds; when I first heard about it, I associated it with rolling around on the forest floor covered in leaves, sticks and mud. If that were the case, I…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to use android fingerprint API

Starting from Android M, fingerprint api was released, this actually ease the stress of typing password,pins or even patterns..

In this article I will go through the basics on how to use fingerprint api..

Basically, fingerprint api is just another implementation of Cryptography,which is encrypting a message with a key..

In Android, for you to make use of the fingerprint api, you have to also provide another security measure(thats is you will have to provide either a PIN, Password or pattern.So this implies that we have to check if there is any other security measures before we can use the fingerprint api..

So, let’s dive straight into it..

Create a new project and set the mini sdk to api level 23(your app can only work on Android 6.0 and above..Ask for Permission to use fingerprint print in appManifest.xml file

as

Before using the fingerprint api, we have to check if this three conditions are meet, these are:

If this three conditions are meet, we are now ready to explore the fingerprint api.

Like I earlier said this is another implementation of cryptography, study this image below:

This is asymmetry cryptography, A system known as the cipher encrypts the the message with a key, when this message gets to the receiver, this same key is then use to decrypt the message.Two questions immediately comes to mind:

Fortunately Android framework provides a keystore facility(to securely store our keys) and a keyGenerator mechanism..So we are going to first generate this keys, store them in the keystore before using this keys to create a cipher for encryption.

To create a keyStore, we first get a new instance, you call a static method getInstance passing in the String parameter “AndroidKeyStore", this equally throws an exception so ensure u catch those exceptions.

Also create an instance of the keyGenerator class, you do this by passing a key algorithm as the first parameter.

Load the keystore and also initialize the keyGenerator, You initialise keyGenetator by calling the init method and passing a keyGenParameterSpec object.a keygenParameterObject sets up some encryption parameters such as the purpose(encrption or decryption), the block modes(in this case I used CBC), also the encryption padding(i used PKCS7 padding)..All this parameters will be used to generate the keys..

Finally create the key:

Create the cipher object, you can do this by calling Cipher.getInstance() method and passing a string called the transformation(parameter used for encryption and this should correspond to the keyGenParameterSpec params)..the transformation string consists of three parts namely:The algorithm, the block and the padding(algorithm/block/padding)..After doing this, get the secrectKeys stored in the Android key store and initialise the cipher by calling the init method on the cipher object and pass the secret key as the second parameter..

Create a CryptoObject using the cipher you just created, this CryptoObject will be passed into one of the overloaded constructor of FingerprintManager.CryptoObject class(other constructors accept Mac and Signature object).

Create a FingerprintManagerHelper class that extends FingerprintManager.AuthenticationCallback, also override the onAuthenticationSuccreded and onAuthenticationFailed methods.. This class is where you make your Fingerprint authentication call, if the users fingerprint matches any fingerprint recorded on the device, then onAuthenticationSucceeded is called, if it doesn't match anyone onAuthenticationFailed is called..You can also override onAuthenticationError this allows you to handle any error(s) encountered during authentication..

So, you can now handle any other authentication logic in onAuthenticationSucceeded method..This will be all for now, to get the full demo code follow this:

Thank you….

Add a comment

Related posts:

Lessons for Achieving Success and Happiness

Lessons for Achieving Success and Happiness. “Ideas are just the beginning — it’s all about execution. It’s not about what you thought about doing, it’s about what you actually did.”.

Can You Start a Business Using Credit Cards?

One of the biggest hurdles to starting a business is generating enough capital to make the initial investment. Even if you have a fantastic idea, with a clear path to revenue and growth, if you don’t…

What is Test Canary?

Implementing test canary deployments in your development process can help you release new features with confidence. By leveraging open-source feature flag tools, like FeatBit, you can achieve…