Skip to content
E3Kit is an SDK that simplifies work with Virgil services and presents the easiest way to add full end-to-end (E2EE) security to their applications to become HIPAA and GDPR compliant and more.
Kotlin Java Shell
Branch: master
Clone or download
Latest commit ca11d8d Jul 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.ci GitHub pages working Apr 16, 2019
ethree-common Added Completable and Result Jun 5, 2019
ethree-kotlin Corrected dependency name in readme Jul 12, 2019
gradle/wrapper Updated tests for new implementation, added sync positive/negative tests Jun 6, 2019
samples Updated Back4App, Nexmo samples to latest e3kit version Jun 19, 2019
tests Updated to new crypto, removed coroutines module Jul 12, 2019
.gitignore Github pages generation Apr 15, 2019
.travis.yml GitHub pages working Apr 16, 2019
CONTRIBUTING.md documentation update Oct 30, 2018
LICENSE.md PR update Feb 12, 2019
README.md Updated snippet Jul 17, 2019
build.gradle
gradlew init Oct 9, 2018
gradlew.bat Change project structure Oct 25, 2018
settings.gradle Updated to new crypto, removed coroutines module Jul 12, 2019

README.md

Virgil E3Kit Android SDK

Build Status GitHub license

Introduction | SDK Features | Installation | Usage Examples | Samples | License | Docs | Support

Introduction

Virgil Security provides the E3Kit SDK which simplifies work with Virgil services and presents an easy-to-use API for adding a security layer to any application. E3Kit interacts with Virgil Cards Service, Keyknox Service and Pythia Service. Virgil E3kit allows you to setup user encryption with multidevice support in just a few simple steps.

SDK Features

  • multi-device support
  • group chats
  • manage users' Public Keys

Installation

You can install E3Kit SDK using Gradle. Please, choose package that suits best for your needs:

Package Description
E3Kit Standard package for Java/Kotlin with methods responses in callbacks

Usage Examples

Initialize e3kit

In order to interact with the Virgil Cloud, the Virgil e3kit SDK must be provided with a callback that it will call to fetch the Virgil JWT from your backend for the current user.

lateinit var eThree: EThree

// Listener for E3Kit initialization
val initializeListener =
    object : OnResultListener<EThree> {
        override fun onSuccess(result: EThree) {
            // Init done!
            eThree = result
        }

        override fun onError(throwable: Throwable) {
            // Error handling
        }
    }

// initialize E3Kit
EThree.initialize(context, virgilTokenCallback).addCallback(initializeListener)

Register user

Use the following lines of code to register a user:

// TODO: Initialize e3kit

val registerListener =
    object : OnCompleteListener {
        override fun onSuccess() {
            // User private key loaded, ready for end-to-end encrypt!
        }

        override fun onError(throwable: Throwable) {
            // Error handling
        }
    }

eThree.register().addCallback(registerListener)

This function generates PrivateKey/PublicKey keypair, saves PrivateKey locally on device and publishes PublicKey to Virgil Cards Service.

Sign and encrypt data/text

This method signs the data/text with the sender's private key and encrypts the message for recipients' public key(s).

// TODO: Initialize e3kit, Register e3kit user          

val lookupKeysListener =
    object : OnResultListener<LookupResult> {
        override fun onSuccess(result: LookupResult) {
            val text = "I was text but become byte array"
            val data = text.toByteArray()

            // Encrypt data using user public keys
            val encryptedData = eThree.encrypt(data, result)

            // Encrypt message using user public keys
            val encryptedText = eThree.encrypt(text, result)
        }

        override fun onError(throwable: Throwable) {
            // Error handling
        }
    }

// Lookup destination user public keys
eThree.lookupPublicKeys(listOf("userUID1", "userUID2", "userUID3")).addCallback(lookupKeysListener)

Decrypt data/text and verify signature

This method decrypts the data using the recipient's private key and verifies authenticity of the decrypted data with sender's public key.

// TODO: Initialize e3kit, Register e3kit user 

val lookupKeysListener =
    object : OnResultListener<LookupResult> {
        override fun onSuccess(result: LookupResult) {
            // Decrypt data and verify if it was really written by Bob
            val decryptedData = eThree.decrypt(encryptedData, result["bobUID"])

            // Decrypt text and verify if it was really written by Bob
            val decryptedText = eThree.decrypt(encryptedText, result["bobUID"])
        }

        override fun onError(throwable: Throwable) {
            // Error handling
        }
    }

// Lookup chat room member key
eThree.lookupPublicKeys("bobUID").addCallback(lookupKeysListener)

Encrypt & decrypt large files

If the data that needs to be encrypted is too large for your RAM to encrypt all at once, use the following snippets to encrypt and decrypt streams.

Stream encryption doesn’t sign the data. This is why stream decryption doesn’t require VirgilPublicKey for verification unlike the general data decryption.

Encryption:

// TODO: initialize and register user (see EThree.initialize and EThree#register)

// Listener for keys lookup
val lookupKeysListener =
        object : OnResultListener<LookupResult> {
            override fun onSuccess(result: LookupResult) {
                val assetManager = context.assets

                assetManager.open("some_file.txt").use { inputStream ->
                    ByteArrayOutputStream().use { outputStream ->
                        // Encrypt input stream using user public keys and writes output to the output stream
                        eThree.encrypt(inputStream, outputStream, result)
                    }
                }
            }

            override fun onError(throwable: Throwable) {
                // Error handling
            }
        }

// Lookup destination user public keys
eThree.lookupPublicKeys(listOf("userUID1", "userUID2", "userUID3")).addCallback(lookupKeysListener)

Decryption:

// TODO: init SDK and register users - see EThree.initialize and EThree#register
ByteArrayOutputStream().use { outputStream ->
    // Decrypt encrypted input stream and writes output to the output stream
    eThree.decrypt(encryptedStream, outputStream)
}

Samples

You can find the code samples for Java and Kotlin here:

Sample type
Android Java
Android Kotlin
Android Java Firebase
Android Kotlin Firebase
Android Kotlin Back4App
Android Kotlin Nexmo

You can run any of them on an emulator to check out the example of how to initialize the SDK, register users and encrypt messages using the E3Kit.

License

This library is released under the 3-clause BSD License.

Docs

Virgil Security has a powerful set of APIs, and the documentation below can get you started today.

Support

Our developer support team is here to help you. Find out more information on our Help Center.

You can find us on Twitter or send us email support@VirgilSecurity.com.

Also, get extra help from our support team on Slack.

You can’t perform that action at this time.