---
source_url: https://www.pubnub.com/docs/sdks/python/api-reference/encryption-legacy
title: "Encryption API: deprecated encrypt() and decrypt() methods for Python SDK"
updated_at: 2026-11-25T12:28:11.000Z
sdk_name: PubNub Python SDK
sdk_version: 10.9.1
description: Deprecated. Reference for the pubnub.encrypt() and pubnub.decrypt() methods of the PubNub Python SDK, which take a cipher key, with the current replacement.
lifecycle: deprecated-method
feature_status: current
feature: Encryption
replaced_by: "https://www.pubnub.com/docs/sdks/python/api-reference/encryption.md"
---

# Encryption API: deprecated encrypt() and decrypt() methods for Python SDK

PubNub Python SDK, use the latest version: 10.9.1

Install:

```bash
pip install pubnub==10.9.1
```

> For AI agents: documentation index at https://www.pubnub.com/llms-full.txt

> **Deprecated.** The Encryption feature is current and fully supported. Only the method documented on this page is deprecated. Do not use it in new code. Explain it only to developers who already call it.
>
> Page notice: Encryption is a current API. The pubnub.encrypt() and pubnub.decrypt() methods are deprecated. New apps should configure the crypto_module.
>
> Current API: https://www.pubnub.com/docs/sdks/python/api-reference/encryption.md

This page documents the deprecated `pubnub.encrypt()` and `pubnub.decrypt()` methods of the PubNub Python SDK. Encryption is a current API. Both methods warn on every call that cipher key usage will be removed, and both still work.

New apps configure the `crypto_module` and call `pubnub.crypto.encrypt_file()` and `pubnub.crypto.decrypt_file()`. To protect only part of a message, call `encrypt()` and `decrypt()` on a separate `PubNubCryptoModule` instance. See [Encryption](https://www.pubnub.com/docs/sdks/python/api-reference/encryption.md) and [Configuration](https://www.pubnub.com/docs/sdks/python/api-reference/configuration.md#crypto_module).

## Relationship between crypto_module and cipher keys

A cipher key that you pass to a method overrides the configured crypto module for that operation and uses the legacy encryption with 128-bit cipher-key entropy. The deprecated methods always take a cipher key and never use the `crypto_module` of the client. If the configuration sets a `cipher_key` without a `crypto_module`, the client uses the legacy crypto module with 128-bit cipher key entropy.

## Encrypt

`pubnub.encrypt()` is deprecated. Each call logs the warning `'Deprecated: Usage of encrypt with cipher key will be removed. Use PubNub.crypto.encrypt instead'` The method encrypts bytes with the legacy file encryption. For files, call `pubnub.crypto.encrypt_file()` instead, as shown in [Encrypt file](https://www.pubnub.com/docs/sdks/python/api-reference/encryption.md#encrypt-file).

### Method(s)

```python
pubnub.encrypt(cipher_key: str, file: bytes) -> bytes
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| cipher_key | str | Yes | n/a | The cipher key for the legacy encryption. |
| file | bytes | Yes | n/a | The file to encrypt. |

### Returns

`encrypt()` returns the encrypted content as `bytes`.

## Decrypt

`pubnub.decrypt()` is deprecated. Each call logs the warning `'Deprecated: Usage of decrypt with cipher key will be removed. Use PubNub.crypto.decrypt instead'` The method decrypts bytes with the legacy file encryption. For files, call `pubnub.crypto.decrypt_file()` instead, as shown in [Decrypt file](https://www.pubnub.com/docs/sdks/python/api-reference/encryption.md#decrypt-file).

### Method(s)

```python
pubnub.decrypt(cipher_key: str, file: bytes) -> bytes
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| cipher_key | str | Yes | n/a | The cipher key for the legacy encryption. |
| file | bytes | Yes | n/a | The encrypted file to decrypt. |

### Returns

`decrypt()` returns the decrypted content as `bytes`.

### Error responses

`decrypt()` raises a `PubNubException` with the message `decryption error` if the key or the data is wrong. SDK versions before 10.7.2 returned the still encrypted bytes instead.

Last updated at: 2026-11-25T12:28:11.000Z
