> ## Documentation Index
> Fetch the complete documentation index at: https://infisical.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Encrypt data

> Encrypt data with a KMS key from the Python SDK.

`client.kms.encrypt_data()` encrypts data with a key in a [KMS](https://infisical.com/docs/documentation/platform/kms/overview.md) project.

## Parameters

**key\_id** `str` *required*

The ID of the key.

**base64EncodedPlaintext** `str` *required*

The data to encrypt, encoded in base64.

## Returns

**ciphertext** `str`

The encrypted data, which [`decrypt_data`](https://infisical.com/docs/sdks/languages/python/kms/decrypt) takes.

```python Basic theme={"dark"}
import base64

ciphertext = client.kms.encrypt_data(
    key_id="<key-id>",
    base64EncodedPlaintext=base64.b64encode(b"4242 4242 4242 4242").decode(),
)
```

```json Response theme={"dark"}
"vnHhD3Lr7tYx0Q2Jm8hZbW5pK1cRf4sNq9aUeO6gT3yVdXlB0iEwCjM7zPkHuGs"
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.