Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python cryptography libraries encrypt data, sign and verify messages, and hash passwords. A high-level recipe chooses the algorithm and its parameters for the caller rather than exposing each primitive. These libraries let apps and services protect stored data, secrets, and user passwords.
Popularity
cryptography has the most monthly downloads in this comparison, at 1.4B.
def verify(self, msg, sig):
if not self.is_public():
warnings.warn("Attempting to verify a message with a private key. " "This is not recommended.")
try:
pyrsa.verify(msg, sig, self._prepared_key)
return True
except pyrsa.pkcs1.VerificationError:
return False
PyNaCl
Exposes the libsodium cryptography library through Python bindings.
Downloads / mo
177.2M
Stars
1.2K
Last release
1.6.2
License
Apache-2.0
Runs on
libsodium
Strengths
Includes authenticated message encryption.Use SecretBox or Aead to encrypt and authenticate messages.
Includes memory-hard password hashing.Use Argon2id, Argon2i, or scrypt through nacl.pwhash.
Limitations
Password keys need saved parameters.Store the salt, chosen derivation function, and its cost settings.
def _encrypt_aead_xchacha20_poly1305_rtpsize(self, header: bytes, data) -> bytes:
# Esentially the same as _lite # Uses an incrementing 32-bit integer which is appended to the payload # The only other difference is we require AEAD with Additional Authenticated Data (the header) box = nacl.secret.Aead(bytes(self.secret_key))
nonce = bytearray(24)
nonce[:4] = struct.pack('>I', self._incr_nonce)
self.checked_add('_incr_nonce', 1, 4294967295)
return header + box.encrypt(bytes(data), bytes(header), bytes(nonce)).ciphertext + nonce[:4]
bcrypt
Hashes and checks passwords with bcrypt.
Downloads / mo
175.9M
Stars
1.5K
Last release
5.0.0
License
Apache-2.0
Strengths
Tunes password-hashing work.Set the work factor when generating a salt.
Derives OpenSSH-compatible keys.Use bcrypt.kdf for OpenSSH’s password-based key derivation.
Limitations
Long passwords raise errors.Validate encoded password length before calling hashpw.
New password storage favors alternatives.Consider Argon2id or scrypt for new password-storage designs.
def passwd(passphrase=None, algorithm="argon2"):
"""Generate hashed password and salt for use in server configuration.
In the server configuration, set `c.ServerApp.password` to
the generated string.
Parameters
---------- passphrase : str
Password to hash. If unspecified, the user is asked to input
and verify a password.
algorithm : str
Hashing algorithm to use (e.g, 'sha1' or any argument supported
by :func:`hashlib.new`, or 'argon2').
Returns
------- hashed_passphrase : str
Hashed password, in the format 'hash_algorithm:salt:passphrase_hash'.
Examples
-------- >>> passwd("mypassword") # doctest: +ELLIPSIS
'argon2:...'
"""
if passphrase is None:
for _ in range(3):
p0 = getpass.getpass("Enter password: ")
p1 = getpass.getpass("Verify password: ")
if p0 == p1:
passphrase = p0
break
warnings.warn("Passwords do not match.", stacklevel=2)
else:
msg = "No matching passwords found. Giving up."
raise ValueError(msg)
if algorithm == "argon2":
import argon2
ph = argon2.PasswordHasher(
memory_cost=10240,
time_cost=10,
parallelism=8,
)
h_ph = ph.hash(passphrase)
return f"{algorithm}:{h_ph}"
h = hashlib.new(algorithm)
salt = ("%0" + str(salt_len) + "x") % random.getrandbits(4 * salt_len)
h.update(passphrase.encode("utf-8") + salt.encode("ascii"))
return f"{algorithm}:{salt}:{h.hexdigest()}"
ecdsa
Signs and verifies ECDSA signatures in pure Python.
from passlib.context import CryptContext
context = CryptContext(schemes=["pbkdf2_sha512"])
hash = context.hash("password")
FAQ
cryptography suits most applications, with authenticated encryption recipes and lower-level primitives. argon2-cffi and bcrypt suit password storage. PyNaCl suits code that wants the fixed choices of libsodium.
PyCryptodome is a self-contained package of low-level ciphers, signatures, message authentication codes, and key derivation functions. The caller chooses the cipher mode and parameters for each operation.
Passlib is a password hashing framework that selects, verifies, and migrates between many hash schemes.
bcrypt generates password records that store the cost factor and salt inside the encoded bytes, then verifies passwords against them. It focuses on password storage rather than general encryption.
PyNaCl is a Python binding to libsodium with authenticated symmetric encryption, public-key signatures, and password hashing helpers.
For coding agents
Found your cryptography library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.