Those functions are free functions exported by the Tanker package, they can be imported individually as follows:

import { toBase64, fromBase64 } from '@tanker/client-browser';
// or...
const { toBase64, fromBase64 } = require('@tanker/client-browser');

The encoding and decoding functions are convenience functions used internally by Tanker. They replace limited implementations provided by the different environments Tanker runs on.

Those functions are extra utilities included in the Tanker SDK, they can be imported individually as follows:

import io.tanker.api.Tanker;

Those functions are extra utilities included in the Tanker SDK, they can be imported individually as follows:

@import Tanker;

Base64 to buffer

function toBase64(bytes: Uint8Array): b64string
function fromBase64(str: b64string): Uint8Array

Converts an array of bytes to a base64-encoded JavaScript string and back. Those are typically used when sending and receiving text from the browser to a remote server:

// Receive and decrypt
const encryptedText = api.receiveText();
const encryptedData = fromBase64(encryptedText);
const clearText = await tanker.decrypt(encryptedData);

// Encrypt and send
const encryptedData = await tanker.encrypt(clearText);
const encryptedText = toBase64(encryptedData);
api.sendText(encryptedText);

Note

Please note that JavaScript's atob() and btoa() are not suited to work with UInt8Array's and unicode data. more details on the mozilla website.

Note

Not needed, use the built-ins.

Note

Not needed, use the built-ins.

Channels

Applies to Android only.

Applies to Android only.

While the channels package is available from API level 1, AsynchronousByteChannel and a few other interfaces are only available in API level 26.

Tanker supports API level 19, therefore it cannot use the newest APIs directly. Instead, it exposes very similar interfaces.

TankerCompletionHandler

// available from io.tanker.api.TankerCompletionHandler

public interface TankerCompletionHandler<V, A> {
  public void completed(
    @NotNull V result,
    @NotNull A attachment
  );

  public void failed(
    @NotNull Throwable result,
    @NotNull A attachment
  );
}

API level 19-compatible CompletionHandler.

TankerAsynchronousByteChannel

// available from io.tanker.api.TankerAsynchronousByteChannel

public interface TankerAsynchronousByteChannel {
  public <A> void read(
    @NotNull ByteBuffer dst,
    @NotNull A attachment,
    @NotNull TankerCompletionHandler<Integer, ? super A> handler
  );
}

API level 19-compatible AsynchronousByteChannel.

Note

There are other functions in the API 26 version, but TankerAsynchronousByteChannel has no use for them.

Helper functions

Tanker provides helpers to:

  • convert streams to Tanker channels and vice versa
  • convert Tanker channels to API level 26 channels and vice versa
// available from io.tanker.api.TankerChannels

public class TankerChannels {
  @NotNull
  public static InputStream toInputStream(
    @NotNull
    TankerAsynchronousByteChannel channel
  );

  @NotNull
  public static TankerAsynchronousByteChannel fromInputStream(
    @NotNull InputStream stream
  );

  @RequiresApi(26)
  @NotNull
  public static AsynchronousByteChannel toAsynchronousByteChannel(
    @NotNull
    TankerAsynchronousByteChannel channel
  );

  @RequiresApi(26)
  @NotNull
  public static TankerAsynchronousByteChannel fromAsynchronousByteChannel(
    @NotNull
    AsynchronousByteChannel channel
  );
}