Skip to main content
Encryption is an experimental feature and is not production ready. Do not use it for critical data.
Turso supports encryption at rest for database files. When enabled, the database file is encrypted using the specified cipher and key. The encryption feature must be explicitly enabled with a command-line flag.

Enabling encryption

Pass the --experimental-encryption flag when opening a database:
tursodb --experimental-encryption database.db

Generating a key

Generate a secure 32-byte key encoded as a hex string:
openssl rand -hex 32
Example output:
2d7a30108d3eb3e45c90a732041fe54778bdcf707c76749fab7da335d1b39c1d
Store this key securely. If you lose it, the database cannot be recovered.

Setting the cipher and key

After opening a new database with --experimental-encryption, set the cipher and key using PRAGMA statements before any other operations:
PRAGMA cipher = 'aegis256';
PRAGMA hexkey = '2d7a30108d3eb3e45c90a732041fe54778bdcf707c76749fab7da335d1b39c1d';

Supported ciphers

CipherDescription
aegis256AEGIS-256 authenticated encryption. Recommended for new databases.
aes256gcmAES-256-GCM authenticated encryption.

URI format

You can provide encryption parameters directly in a URI when opening the database. This is also the required format for reopening an already-encrypted database.
tursodb --experimental-encryption \
  "file:database.db?cipher=aegis256&hexkey=2d7a30108d3eb3e45c90a732041fe54778bdcf707c76749fab7da335d1b39c1d"
To reopen an already-encrypted database, you must use the URI format with cipher and hexkey as URI parameters. Opening the file by path alone without these parameters will fail.

Example: creating and reopening an encrypted database

1

Generate a key

openssl rand -hex 32
# 2d7a30108d3eb3e45c90a732041fe54778bdcf707c76749fab7da335d1b39c1d
2

Create the encrypted database

tursodb --experimental-encryption database.db
Then in the SQL shell:
PRAGMA cipher = 'aegis256';
PRAGMA hexkey = '2d7a30108d3eb3e45c90a732041fe54778bdcf707c76749fab7da335d1b39c1d';

CREATE TABLE secrets (id INTEGER PRIMARY KEY, value TEXT);
INSERT INTO secrets VALUES (1, 'top secret');
3

Reopen the encrypted database

Use the URI format with cipher and hexkey parameters:
tursodb --experimental-encryption \
  "file:database.db?cipher=aegis256&hexkey=2d7a30108d3eb3e45c90a732041fe54778bdcf707c76749fab7da335d1b39c1d"

Build docs developers (and LLMs) love