+++
title = "Encryption and Security"
weight = 10
+++

Meshy implements end-to-end encryption for all message types.

## Direct Messages

Direct (peer-to-peer) messages use public key cryptography:
- Each device has a unique Ed25519 key pair (32-byte public key, 32-byte private key).
- Messages are encrypted using the recipient's public key.
- Only the recipient's private key can decrypt the message.
- Message integrity is verified through cryptographic signatures.

## Channel Messages

Channel messages use symmetric encryption with pre-shared keys:
- **Public channels:** Use a fixed, well-known PSK (everyone can read).
- **Hashtag channels:** PSK derived via SHA-256 hash of the channel name (anyone who knows the name can derive the key).
- **Private channels:** Use a random or user-provided 16-byte PSK (only shared members can read).

Encryption scheme (encrypt-then-MAC):
1. **AES-128-ECB** encryption of the message content.
2. **HMAC-SHA256** MAC (truncated to 2 bytes) computed over the ciphertext for authentication.
3. MAC is verified on receipt before decryption.

## Transport Security

- **BLE:** Nordic UART Service (NUS) with Bluetooth LE security (pairing, encryption at link layer).
- **USB:** No transport encryption (physical connection assumed secure).
- **TCP:** No transport encryption by default (use VPN/SSH tunnel for network security).

## Key Management

- Private keys never leave the device.
- Public keys are shared freely via advertisements and contact exports.
- Channel PSKs are stored locally in the SQLite database.
- Backup files contain PSKs in plaintext (protect backup files accordingly).
