# Message Encryption

Stream Chat encrypts every message in transit and at rest. For message text that Stream itself can't read, your app adds its own encryption on top, with keys your server controls. This works with every Stream Chat client SDK.

## Do any hosted chat SDKs offer end-to-end encryption, or would I need to implement something like the Signal Protocol myself? What would you recommend?

Most apps that ask for end-to-end encryption need message text that the chat provider can't read, not the Signal Protocol. With Stream Chat, your server hands out one key per channel to that channel's members, and your app encrypts message text before sending it and decrypts it after it arrives. Stream stores and delivers only the encrypted text. You don't build a messaging protocol: Stream still handles delivery, history, unread counts and push notifications.

Implement the Signal Protocol or MLS yourself only when your own servers must not be able to read messages either. That brings hard trade-offs, described [below](#device-to-device-encryption).

For video and audio calls, [Stream Video has end-to-end encryption built in](https://getstream.io/video/docs/javascript/guides/end-to-end-encryption/).

## What Stream encrypts

| Where                    | How                                                                                                                                                                                                                                                      |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| In transit               | The API accepts only HTTPS and secure WebSocket connections, with TLS 1.2 or 1.3. Plain HTTP and older TLS versions are refused. Traffic between Stream's [edge and origin servers](https://getstream.io/chat/docs/go-golang/architecture-and-benchmark/) is encrypted too. |
| At rest                  | Stored data, including messages, is encrypted with customer-managed encryption keys in Cloud KMS, which only Stream manages. Off-site backups are encrypted too. See [Security](https://getstream.io/security/).                                                             |
| Message text, end to end | Not built in. Your app encrypts it with keys from your server, as described below.                                                                                                                                                                       |

Encryption in transit and at rest protects messages on the network and on disk. Stream's services can still read them, which features such as search, moderation and translation need.

## Three kinds of end-to-end encryption

| Requirement                                          | Who can read messages                | How                                                                    |
| ---------------------------------------------------- | ------------------------------------ | ---------------------------------------------------------------------- |
| Messages are protected on the network and on disk    | Channel members, your server, Stream | Built in.                                                              |
| Stream can't read messages, and you control the keys | Channel members, your server         | Your app encrypts message text with per-channel keys from your server. |
| Only the people in the chat can read messages        | Channel members only                 | Device-to-device encryption, such as the Signal Protocol or MLS.       |

## Encrypt message text with your own keys

This approach works the same way on every platform, because it only uses what every Stream Chat SDK has: message custom data and a way to change how messages are sent and shown.

1. Your server keeps a secret and derives one key per channel from it.
2. Your app asks your server for a channel's key. Your server checks with Stream that the user is a member of that channel before it answers.
3. Before sending, your app encrypts the message text, puts the encrypted text in the message's custom data and sends a placeholder, such as "Encrypted message", as the text.
4. When a message arrives, your app decrypts the custom data and shows the real text.
5. When someone is removed from a channel or banned, your server switches the channel to a new key, so they can't read new messages.

Your server also needs a channel type for encrypted channels, with the features that read message text turned off, and a push notification template with generic text. [Set up your server](https://getstream.io/chat/docs/sdk/flutter/guides/message-encryption/server/) shows each of these with the Node.js SDK, and they apply to every client platform.

Guides and examples by platform:

- **Flutter:** [Message Encryption](https://getstream.io/chat/docs/sdk/flutter/guides/message-encryption/) walks through the whole approach, from the key endpoint to showing decrypted messages, with a go-live checklist.
- **React Native:** [Build a secure React Native chat app with end-to-end encryption](https://getstream.io/blog/react-native-encrypted-chat/) keeps a key pair on each device and agrees on keys between users, the device-to-device approach below.
- **React:** [End-to-end encryption with Seald](https://getstream.io/blog/react-app-encryption/) uses a key management service with Stream Chat React.
- **iOS, Android and other SDKs:** use the same server, and encrypt and decrypt where your app sends and shows messages.

Have a security expert review your implementation before you release it. Encryption is easy to get wrong in ways that make it unsafe.

## What stops working

Features that read message text only see the placeholder:

- message search
- link previews
- slash commands
- automatic translation
- Stream's AI moderation. Your server can read messages, so it can moderate them instead.
- reading messages in the Stream Dashboard
- message text in push notifications, unless your app decrypts it on the device

Stream still sees who is in each channel, who sent each message and when, reactions and read state, because it needs them to deliver messages. Attachments, channel names and other custom data stay readable unless you encrypt them too.

## Device-to-device encryption

With the Signal Protocol or MLS, each device holds its own keys, and your server never sees them. Stream stores and delivers the encrypted messages as with the approach above. The cost:

- A new device can't read messages sent before it joined, unless you build key backup or device-to-device history transfer.
- Shared inboxes, support teams and bots need their own devices and keys.
- Neither Stream nor your server can moderate, search or audit conversations.

Choose it only when your own servers must not be able to read messages.

## Going further

- [Security](https://getstream.io/security/): how Stream protects your data, and its certifications.
- [End-to-end encryption](https://getstream.io/glossary/end-to-end-encryption-e2ee/): the terms used on this page.
- [Channel Types](https://getstream.io/chat/docs/go-golang/channel-features/): the features each channel type turns on or off.

---

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/go-golang/message-encryption/](https://getstream.io/chat/docs/go-golang/message-encryption/).