pysodium is a Python wrapper for the `libsodium` cryptography library, providing high-level cryptographic primitives for tasks like encryption, decryption, signatures, and key derivation. The library aims to offer a simple interface, often aligning with the PyNaCl API, and handles buffer management for ease of use in Python. It is currently at version 0.7.18 and receives regular updates, with new features and security fixes introduced periodically.
pip install pysodiumVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic symmetric (secret-key) encryption and decryption using `crypto_secretbox` and `crypto_secretbox_open`, and asymmetric (public-key) key pair generation using `crypto_box_keypair`.
Upgrade to pysodium >= 0.7.17. Ensure your application's message handling respects the corrected maximum message sizes.
Install `libsodium` system-wide using your operating system's package manager (e.g., `apt install libsodium-dev` on Debian/Ubuntu, `brew install libsodium` on macOS, or build from source on Windows).
Upgrade to pysodium >= 0.7.15. Review any code that explicitly checks the return value of `keygen()` functions to ensure it aligns with the corrected behavior (which typically means these functions now directly return the key material or raise an error on failure).
Run `pip install pysodium` to install the package.
Install the `libsodium` development package for your operating system (e.g., `sudo apt-get install libsodium-dev` on Debian/Ubuntu, `brew install libsodium` on macOS). For Windows, you'll need to download and install the pre-compiled `libsodium` binaries or compile from source, ensuring the `libsodium.dll` is discoverable by Python (e.g., in PATH).
Ensure the `key`, `nonce`, and `ciphertext` are exactly the same as those used during encryption. Verify that no data corruption or malicious modification has occurred during transmission or storage. If using public-key cryptography, ensure the correct sender's public key and receiver's secret key are used.