An Android implementation of the Libsodium cryptography library. For the lazy dev.
Clone or download

Lazysodium for Android

Lazysodium is a complete Android implementation of the Libsodium library that provides developers with a smooth and effortless cryptography experience.


Why Lazysodium

We created Lazysodium because we really wanted a solid cryptography library that would just work without fuss.

We were exasperated and annoyed with current Libsodium implementations as some of them were just poorly maintained, poorly managed and, plain and simply, poorly architected.

Thus, Lazysodium was born with the blessings of Lazycode, a part of Terl that specialises in giving developers easy-to-use software and tools that just work. Read more about us below.

The difference in code

We believe the code speaks for itself. Compare the two ways you could use Lazysodium:

1. Using native functions

byte[] subkey = subkey[32];
byte[] context = "Examples".getBytes(StandardCharsets.UTF_8);
byte[] masterKey = "a_master_key".getBytes(StandardCharsets.UTF_8);
int result = lazySodium.cryptoKdfDeriveFromKey(subkey, subkey.length, 1L, context, masterKey);

// Now check the result
if (res == 0) {
    // We have a positive result. Let's store it in a database.
    String subkeyString = new String(subkey, StandardCharsets.UTF_8);

2. Or use Lazysodium's lazy functions

You could use the above native functions or you could use the "Lazy" functions πŸ˜„

String context = "Examples";
String masterKey = "a_master_key";
String subkeyString = lazySodium.cryptoKdfDeriveFromKey(1L, context, masterKey);
// Now store in database or something

As you can see Lazysodium's lazy functions save you a lot of pain!


You can find an up-to-date feature list here.

Quick start

This is by no means a comprehensive introduction to Lazysodium. Please view the official documentation for a more comprehensive guide.

1. Install

Install by adding the bintray repository and the dependency.

// Top level build file
repositories {
    maven {
        url  ""

// Add to dependencies section
dependencies {
    implementation "com.goterl.lazycode:lazysodium-android:VERSION_NUMBER@aar"
    implementation ""

Substitute VERSION_NUMBER for the version in this box:


Substitute JNA_VERSION for the latest JNA version.

2. Let's go!

You can now initialise and start encrypting! Please note that this library follows the official libsodium docs closely. You need to use those docs to help you find the functions you need.

// Let's initialise LazySodium, perhaps in an Application class somewhere
LazySodiumAndroid lazySodium = new LazySodiumAndroid(new SodiumAndroid());

// Now you can cast to an interface so that our
// IDE picks up and intelligently loads up the correct methods. 
SecretBox.Native secretBoxNative = (SecretBox.Native) lazySodium;
SecretBox.Lazy secretBoxLazy = (SecretBox.Lazy) lazySodium;

// The first one is Lazysodium's Native implementation which
// is just like libsodium's native C function but with tiny enhancements
// to make your life easier.
// Convert key to string and save to DB

// This one is Lazysodium's Lazy implementation which makes
// your work with cryptography super easy.
String key = secretBoxLazy.cryptoSecretBoxKeygen();

In the above code there are two ways you can use Lazysodium. The first way is through the Native interface. The second is through the Lazy interface.

3. You decide

Every project is different, you may need to use lower-level APIs to achieve the control you need so you use the Native interface. Or alternatively you just don't want to deal with the details so you stick to the Lazy interface.

Every interface you can cast to is helpfully all in one directory so you can easily pick the functions you need. This isolates your code and prevents you from making mistakes.

Important: If possible, please stick to using either the Native or the Lazy interface. The reason for this is that the Lazy interface normally converts everything to hexadecimal whereas the Native interface assumes everything is non-hexadecimal. If you don't know what you're doing, you could end up making mistakes.


See our official documentation to get started.


You can preview some of the features in our free Lazysodium app available on Google Play:

Get it on Google Play

Lazysodium for Java

We also have a Java implementation available at Lazysodium for Java. It has the same API as this library so you can share code easily!

Help us grow

Lazysodium needs your support for it to continue being maintained and improved. Even if you put forward Β£1/$1/€1 it still means a lot for us. Your money would go into improving our open-source projects first and foremost.

Patreon Terl Supporters
One-time βœ— βœ“
Weekly βœ— βœ“
Monthly βœ“ βœ“
Yearly βœ— βœ“
Rewards βœ“ βœ“
Currencies USD 100+ currencies

Who are we?

Created by the wizards at Terl.