Skip to content
Nodes Encryption Library
Java Kotlin
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
app Updated README & Exposed HardwareManager May 7, 2018
settings.gradle Migrated most of the classes to Java Jan 5, 2018

Locksmith Badge


Nodes Encryption library using the Android KeyStore

🔧 Installation

Installation is pretty simple just add the following line to your gradle dependecies (See badge for current version)

  implementation 'dk.nodes.locksmith:core:x.x.+'


The library itself is written in Java but most of the examples you'll find here (including the sample app itself) is written in kotlin. The aim of the library is to simplify and have the same fingerprint authentication and encryption process across all of our apps

Getting Started

Step 1) Initiate Library
    override fun onCreate() {
        // Configure our Locksmith instance
        val locksmithConfiguration = LocksmithConfiguration()
        locksmithConfiguration.keyValidityDuration = 120
        // Start our locksmith instance
        Locksmith.init(this, locksmithConfiguration)

Using Fingerprint Auth

Next section will cover using the fingerprint encryption portion of the Library if you're not going to use this just skip to the next section

Step 1) Show Dialog
    // This only needs to be done if you enabled Fingerprint auth on the config section
    private fun showFingerprintDialog(){
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    .setEventListener(this) // Sets the event listener for our dialog

After setting up the dialog and showing it, the authentication process will then be handled by the dialog, and should return a successful event or an error even see the following section for events and types.

Note: You are also able to extend the FingerprintDialogBase or FingerprintAlertDialogBase to write your own custom dialog

Step 2) Add Event Listener

In order to listen to events from the dialog you must implement the OnFingerprintDialogEventListener as shown above.

    override fun onFingerprintEvent(event: FingerprintDialogEvent) {
        when (event) {
            FingerprintDialogEvent.CANCEL           -> {
                Log.w(tag, "CANCEL") // Event fired when user cancels the dialog
            FingerprintDialogEvent.SUCCESS          -> {
                Log.w(tag, "SUCCESS") // Event fired when user successfully authenticated
            FingerprintDialogEvent.ERROR            -> {
                Log.w(tag, "ERROR") // A fingerprint was read but it was an incorrect fingerprint
            FingerprintDialogEvent.ERROR_SECURE     -> {
                Log.w(tag, "ERROR_SECURE") // Device does not have lock screen enabled
            FingerprintDialogEvent.ERROR_HARDWARE   -> {
                Log.w(tag, "ERROR_HARDWARE") // Device does not have fingerprint hardware
            FingerprintDialogEvent.ERROR_ENROLLMENT -> {
                Log.w(tag, "ERROR_ENROLLMENT") // Device has no fingerprints enrolled
            FingerprintDialogEvent.ERROR_CIPHER     -> {
                Log.w(tag, "ERROR_ENROLLMENT") // Error initialization a cipher

The dialog will return the following events

Encrypting Data

For encrypting data you have two main forms of doing so you can either use the fingerprintEncryptionManager or encryptionManager

If you're going to use the fingerprintEncryptionManager you must authenticate first using the method in the first step otherwise the standard encryptionManager

    // Int Encrypt/Decrypt
    // Boolean Encrypt/Decrypt
    // Float Encrypt/Decrypt
    // Long Encrypt/Decrypt

Note: if you're using kotlin you need to be sure to catch LocksmithEncryptionException and handle the errors appropriately (see the section below for how to do that)

####Step 3) Handling Encryption Errors

private fun handleException(e: LocksmithEncryptionException) {
    Log.e(TAG, "handleException")
    when (e.type) {
         * Will return this if for some reason the encryption cipher failed to be initiated
        Initiation -> {}
         * Will return this type if the cipher/algorithm was not properly initiated
        Uninitiated -> {}
         * Will return this type if key has expired 
         * (will usually require you to go through the fingerprint validation sequence again)
        Unauthenticated -> {}
         * Will return this type if the data fed to the encrypt method isn't a valid encrypted message
        InvalidData -> {}
         * Will return this type if the data is too long or the wrong size
        EncryptionError -> {}
         * Thrown when an unknown error is caught
        Generic -> {}

Because of the way Kotlin handles checked exceptions we opted to wrap all exceptions and return a ENUM with the exception as well (makes it easier)

💻 Developers

  • @brianestrada
You can’t perform that action at this time.