Utilities
In addition to the main API, Etebase provides a few utility functions to make development easier.
Base64
Base64 is a popular way to encode binary data to an ASCII string format, and is used throughout Etebase. We use the URL-friendly variant and provide functions to convert to and from it.
- JavaScript
- Python
- Java
- Kotlin
- C/C++
- Rust
const binaryData = Uint8Array.from([1, 2, 3]);
const b64encoded = Etebase.toBase64(binaryData);
const decoded = Etebase.fromBase64(b64encoded);
// decoded is equal to binaryData
from etebase import Base64Url
binary_data = b"test"
b64encoded = Base64Url.to_base64(binary_data);
decoded = Base64Url.from_base64(b64encoded);
# decoded is equal to binary_data
import com.etebase.client.Utils;
byte[] binaryData = "test".getBytes("UTF-8");
String b64encoded = Utils.toBase64(binaryData);
byte[] decoded = Utils.fromBase64(b64encoded);
// decoded is equal to binaryData
import com.etebase.client.Utils
val binaryData = "test".toByteArray()
val b64encoded = Utils.toBase64(binaryData)
val decoded = Utils.fromBase64(b64encoded)
// decoded is equal to binaryData
const char *text = "Test";
// We use +1 because we want to also encode the \0
char encoded[ETEBASE_UTILS_TO_BASE64_MAX_LEN(strlen(text) + 1)];
etebase_utils_to_base64(text, strlen(text) + 1, encoded, sizeof(encoded));
char decoded[ETEBASE_UTILS_FROM_BASE64_MAX_LEN(strlen(encoded))];
uintptr_t decoded_len = 0;
etebase_utils_from_base64(encoded, decoded, sizeof(decoded), &decoded_len);
// decode is equal to text
use etebase::utils;
let binary_data = b"test";
let b64_encoded = utils::to_base64(binary_data)?;
let decoded = utils::from_base64(&b64_encoded)?;
// decoded is equal to binary_data
assert_eq!(decoded, binary_data);
Random bytes
Getting secure random data is at the core of almost every cryptographic operation. Etebase takes care of the cryptography for you so you won't often need to generate random data on your own, but for when you do:
- JavaScript
- Python
- Java
- Kotlin
- C/C++
- Rust
// Wait for Etebase to be ready.
// Note: if you already have an Account instance you don't need to manually wait.
await Etebase.ready;
// Generate 32 random bytes
const randomData = Etebase.randomBytes(32);
from etebase import random_bytes
# Generate 32 random bytes
random_data = random_bytes(32)
import com.etebase.client.Utils;
// Generate 32 random bytes
byte[] randomData = Utils.randomBytes(32);
import com.etebase.client.Utils
// Generate 32 random bytes
val randomData = Utils.randomBytes(32)
// Generate 32 random bytes
char buf[32];
etebase_utils_randombytes(buf, sizeof(buf));
use etebase::utils;
// Generate 32 random bytes
let random_data = utils::randombytes(32);