> For the complete documentation index, see [llms.txt](https://docs.sudoplatform.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sudoplatform.com/guides/telephony/message-privacy-and-key-management.md).

# Message Privacy and Key Management

Understanding how message content is protected determines where in your application a user is able to read their messages.

When a phone number is provisioned, the SDK generates a key pair on the device, registers the public key with the Telephony service, and retains the private key in the device key store. The  service seals the text and the sender's number of each received message to that public key. Reading a message requires the private key to unseal it.

The following characteristics follow from this design.

* Message content is readable only on a device that holds the private key. The Telephony service is unable to read it, and neither is a second device until the key is moved there.
* A reinstalled application, or a second device, is unable to read existing messages until a key archive is imported. See \[Export and Import Cryptographic Keys]#export-and-import-cryptographic-keys).

### Export and Import Cryptographic Keys

Message content is sealed to a key held on a single device meaning a user who reinstalls the application or adds a second device is unable to read their existing messages until the key is moved there.

The `exportKeys` method returns a portable key archive, and the `importKeys` method restores one.

{% tabs %}
{% tab title="Typescript" %}

```js
try {
  // On the device that holds the keys.
  const archive = await telephonyClient.exportKeys()

  // On the device that requires them.
  await telephonyClient.importKeys(archive)
} catch (error) {
  // Handle/notify user of error
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
do {
    /// On the device that holds the keys.
    let archive = try telephonyClient.exportKeys()

    /// On the device that requires them.
    try telephonyClient.importKeys(archiveData: archive)
} catch {
    /// Handle/notify user of error
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
launch {
    try {
        // On the device that holds the keys.
        val archive = withContext(Dispatchers.IO) {
            telephonyClient.exportKeys()
        }

        // On the device that requires them.
        withContext(Dispatchers.IO) {
            telephonyClient.importKeys(archive)
        }
    } catch (e: SudoTelephonyClient.CryptographicKeysException) {
        // Handle/notify user of exception
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Importing an archive replaces the keys on the device rather than merging with them. All existing keys are removed before the archive is restored, so export from the destination device first if it holds keys that are still required.
{% endhint %}
