---
title: 'Text encryption and random tokens'
url: 'https://docs.geens.com/geens-partners/geens-sdk/browser-sdk/text-encryption-and-random-tokens'
markdown: 'https://docs.geens.com/geens-partners/geens-sdk/browser-sdk/text-encryption-and-random-tokens.md'
date: '2026-12-03'
description: "Password-based encryption Both methods accept a nonempty string and a password of at least four characters. Use the encrypted string returned by encryptText as input to decryptText: sdk.encryptText('Hello', 'your-password', onSuccess, onError); sdk.decryptText(encryptedText, 'your-password', onSuc…"
---

# Text encryption and random tokens

[](#)# Text encryption and random tokens

## Password-based encryption

Both methods accept a nonempty string and a password of at least four characters. Use the encrypted string returned by `encryptText` as input to `decryptText`:

```javascript
sdk.encryptText('Hello', 'your-password', onSuccess, onError);
sdk.decryptText(encryptedText, 'your-password', onSuccess, onError);
```

`encryptedText` is the previous encryption result. The quick start above shows the full round trip. These methods do not require a Geens login.

## RSA encryption and decryption

RSA methods require a logged-in user's stored credentials. Pass a public key to encrypt for a specific recipient, or `null` to use the current user's key. The SDK still requires local user data when an explicit public key is provided. Decrypt with the corresponding user's stored private key:

```javascript
sdk.rsaEncryptText('Hello', null, onSuccess, onError);
sdk.rsaDecryptText(rsaEncryptedText, onSuccess, onError);
```

`rsaEncryptedText` is a result from `rsaEncryptText`; RSA supports short payloads, not arbitrary file content.

## Generate a random token

Generates a 32-character token. The first argument excludes individual characters; `true` limits the result to letters and numbers. Ensure the exclusions leave an available alphabet.

```javascript
sdk.generateCryptographicallySafeRandomToken([], true, onSuccess, onError);
```

---

## Navigation

- Parent: [Browser SDK](https://docs.geens.com/geens-partners/geens-sdk/browser-sdk.md)
- Previous: [Sharing and users](https://docs.geens.com/geens-partners/geens-sdk/browser-sdk/sharing-and-users.md)
- Next: [API reference](https://docs.geens.com/geens-partners/geens-sdk/browser-sdk/api-reference.md)
