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

DeprecatedEncryption is a current API. The pubnub.encrypt() and pubnub.decrypt() methods are deprecated. New apps should configure the crypto_module. Go to Encryption

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 and Configuration.

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.

Method(s)​

1pubnub.encrypt(cipher_key: str, file: bytes) -> bytes
required
cipher_key required#
Type: str
Default: no default
The cipher key for the legacy encryption.
file required#
Type: bytes
Default: no default
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.

Method(s)​

1pubnub.decrypt(cipher_key: str, file: bytes) -> bytes
required
cipher_key required#
Type: str
Default: no default
The cipher key for the legacy encryption.
file required#
Type: bytes
Default: no default
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.

Was this page useful?

Last updated on