Double Ratchet Encryption

This feature is available for Swift, Kotlin and Java. It's not yet available for JavaScript.

In this section, you'll find out how to create and manage secure channel sessions between two users using the Double Ratchet algorithm so that each message is separately encrypted.

Find out about Double Ratchet in this guide.

Before you begin

Be sure to implement the following:

Create channel

To establish communication between users, you need to create a peer-to-peer connection first. Use the following snippet to create a channel with Double Ratchet protocol:

ethree.createRatchetChannel(users.get("Bob"))
      .addCallback(new OnResultListener<RatchetChannel>() {
          @Override public void onSuccess(RatchetChannel ratchetChannel) {
              // Channel created and saved locally!
          }

          @Override public void onError(@NotNull Throwable throwable) {
              // Error handling
          }
      });

In this snippet, Alice creates a channel with Bob.

Join channel

Now, after the channel has been created by Alice, Bob (users) can join it:

ethree.joinRatchetChannel(users.get("Alice"))
      .addCallback(new OnResultListener<RatchetChannel>() {
    @Override public void onSuccess(RatchetChannel ratchetChannel) {
        // Channel joined and saved locally!
    }

    @Override public void onError(@NotNull Throwable throwable) {
        // Error handling
    }
});

Get channel

After joining or creating channel, you can use getRatchetChannel method to retrieve it from the local storage:

RatchetChannel channel = ethree.getRatchetChannel(users.get("Alice"));

Delete channel

Use this snippet to delete channel from local storage and delete cloud invite:

ethree.deleteRatchetChannel(users.get("Bob"))
      .addCallback(new OnCompleteListener() {
          @Override public void onSuccess() {
              // Channel was deleted!
          }

          @Override public void onError(@NotNull Throwable throwable) {
              // Error handling
          }
      });

Encrypt and decrypt messages

Use the following code snippet to encrypt messages:

// prepare a message
String messageToEncrypt = "Hello, Bob!";

String encrypted = channel.encrypt(messageToEncrypt);

And the following code snippet to decrypt messages:

String decrypted = channel.decrypt(encrypted);

Limitations

One-to-one communication only

The Double Ratchet algorithm only allows for one-to-one communication. E3Kit provides another secure method that implements end-to-end encryption for many-to-many communication that allows new users to join and instantly have access to previously encrypted data (eg. message history). See our Group Encryption method.