PyNaCl: Python binding to the Networking and Cryptography (NaCl) library

1.6.2 · active · verified Sat Mar 28

PyNaCl is a Python binding to the Networking and Cryptography (NaCl) library, providing cryptographic operations such as digital signatures, secret-key and public-key encryption, hashing, and password-based key derivation. The current version is 1.6.2, released on January 1, 2026. PyNaCl follows a regular release cadence, with updates approximately every 1-2 years.

Warnings

Install

Imports

Quickstart

This example demonstrates how to generate a private key, derive the corresponding public key, create a PublicKeyBox for encryption, and encrypt and decrypt a message using PyNaCl.

from nacl.public import PrivateKey, PublicKey, PublicKeyBox

# Generate a private key
private_key = PrivateKey.generate()

# Derive the corresponding public key
public_key = private_key.public_key

# Create a PublicKeyBox for encryption
box = PublicKeyBox(public_key)

# Encrypt a message
message = b"Secret message"
encrypted = box.encrypt(message)

# Decrypt the message
decrypted = box.decrypt(encrypted)
print(decrypted.decode())

view raw JSON →