Cryptography with Google Tink on Android

Securely storing customer information is really critical to an organisation's success. The customers will be storing some really sensitive information such as passwords, financial data etc. Implementing encryption will prevent unauthorised access to the data and also help with compliance and regulations. 

Implementing cryptography can be complex though and traditional libraries often require extensive coding knowledge about the mathematics behind cryptographic algorithms.

This is exactly where the use case of Google Tink comes into picture. It is a user-friendly, open-source cryptography library which can be used for android app development along with a couple other languages.

What is Google Tink

Tink is a multi-language, cross-platform, open source library that provides secure and easy-to-use cryptographic APIs, and was created and is being maintained by cryptographers and security engineers at Google.

Advantages of using Tink

Tink offers several compelling advantages:

Integrating Tink in Android

Adding Tink to your project is straightforward. Include the dependency in your app-level Gradle file:

Android Keystore

"The Android Keystore system lets you store cryptographic keys in a container to make them more difficult to extract from the device. Once keys are in the keystore, you can use them for cryptographic operations, with the key material remaining non-exportable. Also, the keystore system lets you restrict when and how keys can be used, such as requiring user authentication for key use or restricting keys to use only in certain cryptographic modes." —  developer.android.com

We can use Android Keystore to manage (create, store and retrieve) the cryptographic keys securely and is actually one of the safest and easiest ways to securely manage the keys.

Let's have a look at some code on how to encrypt and decrypt using Tink. You can have a look at the complete code in the Github repo here: https://github.com/ksharma-xyz/TinkAndroidSample

Use Cases for Tink Android

SharedPreferences are quite commonly used to store small key value data in Android. We can use Tink to implement a secure way to save the app data.

It is also quite interesting to note that the library EncryptedSharedPreferences (Link) uses Google Tink underneath in order to provide, so we could use it directly in this case.

Tink can also be used to encrypt files or large streams of data. Read more 

References