# Encryption and storage

> Protect message bodies and private files, and rotate encryption keys.

[Web documentation](https://threads.teamkrope.com/docs/encryption-storage/) · Inner Threads v1.3.0

## Encryption at rest

Message bodies are encrypted by default using Laravel's authenticated AES-256-CBC encrypter. The server decrypts authorized messages for display and search. The host holds the key, so clients do not need to exchange keys.

Keep a dedicated message key if you want its lifecycle separate from Laravel's app key.

```bash
php artisan key:generate --show
```

```dotenv
INNER_THREADS_ENCRYPTION_ENABLED=true
INNER_THREADS_ENCRYPTION_KEY=base64:<your-32-byte-key>
```

When the dedicated key is empty, the package uses `APP_KEY`. Changing `INNER_THREADS_ENCRYPTION_ENABLED` affects new writes. Encrypted rows still need the appropriate key to read.

## Rotate a key

Put the new key in `INNER_THREADS_ENCRYPTION_KEY` and the old keys in the comma-separated `INNER_THREADS_ENCRYPTION_PREVIOUS_KEYS`. Rebuild any cached configuration. Make a database backup before rotation and retain the keys needed to read that backup.

```bash
php artisan inner-threads:reencrypt --dry-run
php artisan inner-threads:reencrypt --force
php artisan inner-threads:reencrypt --dry-run
```

The final dry run should show zero candidates, concurrent changes and failures before removing old keys from active configuration.

## Keep attachments private

Use a Laravel filesystem disk whose files are accessible only through authenticated download routes. The default disk is `local`. Uploads use the configured size and file-count limits. Hosts can restrict file types with the optional MIME allowlist in the [configuration](https://threads.teamkrope.com/docs/configuration/#attachments).

Encryption of stored attachment bytes and database metadata belongs to your storage or database layer. Use HTTPS in production. With message search enabled, the server decrypts a bounded set of authorized recent messages. Website preview text uses the body-encryption setting. Thumbnail bytes and file contents depend on your database or storage encryption.
