API Reference¶
Core API¶
Cryptography Suite Package Initialization.
- exception cryptography_suite.CryptographySuiteError¶
Bases:
Exception
Base exception for the cryptography suite.
- exception cryptography_suite.DecryptionError¶
Bases:
CryptographySuiteError
Raised when decryption fails or invalid data is provided.
- exception cryptography_suite.EncryptionError¶
Bases:
CryptographySuiteError
Raised when encryption fails or invalid parameters are provided.
- class cryptography_suite.HybridEncryptor¶
Bases:
object
Object-oriented helper for hybrid encryption.
- decrypt(private_key: rsa.RSAPrivateKey | x25519.X25519PrivateKey, data: EncryptedHybridMessage | Mapping[str, str | bytes] | str | 'EncryptedMessage') bytes ¶
Decrypt data produced by
encrypt()
.
- encrypt(message: bytes, public_key: RSAPublicKey | X25519PublicKey, *, raw_output: bool = False) EncryptedHybridMessage ¶
Encrypt
message
usinghybrid_encrypt()
.
- exception cryptography_suite.KeyDerivationError¶
Bases:
CryptographySuiteError
Raised when a key derivation operation fails.
- class cryptography_suite.KeyManager¶
Bases:
object
Utility class for handling private key storage and rotation.
- generate_ec_keypair_and_save(private_key_path: str, public_key_path: str, password: str, curve: ~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve = <cryptography.hazmat.primitives.asymmetric.ec.SECP256R1 object>)¶
Generate an EC key pair and save to
private_key_path
andpublic_key_path
.
- generate_ed25519_keypair_and_save(private_key_path: str, public_key_path: str, password: str)¶
Generate an Ed25519 key pair and save to disk.
- generate_ed448_keypair_and_save(private_key_path: str, public_key_path: str, password: str)¶
Generate an Ed448 key pair and save to disk.
- generate_rsa_keypair_and_save(private_key_path: str, public_key_path: str, password: str, key_size: int = 4096)¶
Generate an RSA key pair and save to
private_key_path
andpublic_key_path
.
- load_private_key(filepath: str, password: str | None = None)¶
Load a private key from
filepath
.password
should be provided if the key is encrypted.
- rotate_keys(key_dir: str) None ¶
Generate a new RSA key pair replacing any existing pair in
key_dir
.
- save_private_key(private_key, filepath: str, password: str | None = None) None ¶
Save a private key in PEM format.
If
password
is provided the key is wrapped using AES-256-CBC. If nopassword
is supplied the key is written in cleartext (mode 0600) and a warning is logged. Setting theCRYPTOSUITE_STRICT_KEYS
environment variable toerror
will instead raise aSecurityError
.
- class cryptography_suite.KeyVault(key: bytes | bytearray)¶
Bases:
object
Context manager for sensitive key storage.
Secrets wrapped by
KeyVault
are wiped from memory when the context exits or the object is garbage collected. Plainbytes
values passed around in Python cannot be reliably erased and may linger until the interpreter frees them.
- exception cryptography_suite.MissingDependencyError¶
Bases:
CryptographySuiteError
Raised when an optional dependency is missing.
- exception cryptography_suite.ProtocolError¶
Bases:
CryptographySuiteError
Raised when a protocol implementation encounters an error.
- class cryptography_suite.SPAKE2Client(password: str)¶
Bases:
SPAKE2Party
Client-side implementation of the SPAKE2 protocol.
Computes the shared key using the server’s message.
- generate_message() bytes ¶
Generates the client’s SPAKE2 message.
- class cryptography_suite.SPAKE2Server(password: str)¶
Bases:
SPAKE2Party
Server-side implementation of the SPAKE2 protocol.
Computes the shared key using the client’s message.
- generate_message() bytes ¶
Generates the server’s SPAKE2 message.
- exception cryptography_suite.SignatureVerificationError¶
Bases:
CryptographySuiteError
Raised when signature verification fails.
- exception cryptography_suite.StrictKeyPolicyError¶
Bases:
CryptographySuiteError
Raised when strict key policy prohibits unencrypted PEM usage.
- exception cryptography_suite.UnsupportedAlgorithm¶
Bases:
CryptographySuiteError
Raised when attempting to use an unsupported algorithm.
- cryptography_suite.argon2_decrypt(encrypted_data: str, password: str) str ¶
- cryptography_suite.argon2_encrypt(plaintext: str, password: str) str ¶
- cryptography_suite.audit_log(func: Callable) Callable ¶
Decorator to log cryptographic operations.
- cryptography_suite.available_backends() list[str] ¶
- cryptography_suite.base62_decode(data: str) bytes ¶
Decodes a Base62-encoded string into bytes.
- cryptography_suite.base62_encode(data: bytes) str ¶
Encodes byte data into Base62 format.
- cryptography_suite.blake2b_hash(data: str) str ¶
Generates a BLAKE2b hash of the given data.
- cryptography_suite.blake3_hash(data: str) str ¶
Generates a BLAKE3 hash of the given data.
- cryptography_suite.chacha20_decrypt(encrypted_data: bytes | str, password: str) str ¶
Decrypt data encrypted with ChaCha20-Poly1305.
- cryptography_suite.chacha20_decrypt_aead(ciphertext: bytes, key: bytes, nonce: bytes, *, associated_data: bytes | None = None) bytes ¶
Decrypt data encrypted with
chacha20_encrypt_aead()
.
- cryptography_suite.chacha20_encrypt(plaintext: str, password: str, *, raw_output: bool = False) str | bytes ¶
Encrypt using ChaCha20-Poly1305 with an Argon2-derived key.
- cryptography_suite.chacha20_encrypt_aead(plaintext: bytes, key: bytes, nonce: bytes, *, associated_data: bytes | None = None) bytes ¶
Encrypt
plaintext
using ChaCha20-Poly1305.The
key
must be 32 bytes and thenonce
12 bytes.
- cryptography_suite.constant_time_compare(val1: bytes | bytearray, val2: bytes | bytearray) bool ¶
Return
True
ifval1
equalsval2
using a timing-safe check.
Splits a secret into shares using Shamir’s Secret Sharing.
- cryptography_suite.ct_equal(a, b, /)¶
Return ‘a == b’.
This function uses an approach designed to prevent timing analysis, making it appropriate for cryptography.
a and b must both be of the same type: either str (ASCII only), or any bytes-like object.
Note: If a and b are of different lengths, or if an error occurs, a timing attack could theoretically reveal information about the types and lengths of a and b–but not their values.
- cryptography_suite.decode_encrypted_message(data: str) EncryptedHybridMessage | Mapping[str, bytes] | EncryptedMessage ¶
Parse a Base64 string produced by
encode_encrypted_message()
.
- cryptography_suite.decrypt_file(encrypted_file_path: str, output_file_path: str, password: str, kdf: str = 'argon2') None ¶
Decrypt a file encrypted with AES-GCM using a password-derived key.
Argon2id is used by default when available. Specify
kdf='scrypt'
orkdf='pbkdf2'
if the file was encrypted using one of those KDFs or when Argon2 support is missing.Data is streamed in chunks, verifying the authentication tag at the end. The output file is removed if decryption fails.
- async cryptography_suite.decrypt_file_async(encrypted_file_path: str, output_file_path: str, password: str, kdf: str = 'argon2') None ¶
Asynchronously decrypt a file encrypted with AES-GCM using a password-derived key.
- cryptography_suite.derive_hkdf(key: bytes, salt: bytes | None, info: bytes | None, length: int) bytes ¶
Derive a key using HKDF-SHA256.
- cryptography_suite.derive_key_argon2(password: str, salt: bytes, key_size: int = 32, memory_cost: int = 65536, time_cost: int = 3, parallelism: int = 1) bytes ¶
Derive a key using Argon2id.
The cost parameters default to module constants which may be overridden via the
CRYPTOSUITE_ARGON2_*
environment variables.
- cryptography_suite.derive_key_pbkdf2(password: str, salt: bytes, key_size: int = 32) bytes ¶
Derive a key using PBKDF2 HMAC SHA-256.
- cryptography_suite.derive_key_scrypt(password: str, salt: bytes, key_size: int = 32) bytes ¶
Derive a cryptographic key using Scrypt KDF.
Derives a shared key using X25519 key exchange.
Derives a shared key using X448 key exchange.
- cryptography_suite.ec_decrypt(ciphertext: bytes | str, private_key: X25519PrivateKey) bytes ¶
Decrypt ECIES
ciphertext
usingprivate_key
.The
ciphertext
must contain the ephemeral public key, nonce, and the AES-GCM encrypted payload produced byec_encrypt()
.
- cryptography_suite.ec_encrypt(plaintext: bytes, public_key: X25519PublicKey, *, raw_output: bool = False) str | bytes ¶
Encrypt
plaintext
forpublic_key
using ECIES.This implementation follows best practices:
Generate a fresh ephemeral X25519 key pair.
Derive the ECDH shared secret with the recipient’s public key.
Use HKDF-SHA256 to turn the shared secret into a 256-bit AES key.
Encrypt the plaintext with AES-GCM using a random nonce.
The returned value consists of the ephemeral public key, nonce, and ciphertext concatenated together.
- cryptography_suite.encode_encrypted_message(message: EncryptedHybridMessage | Mapping[str, bytes | bytearray]) str ¶
Convert a hybrid or Signal encrypted message into a Base64 string.
- cryptography_suite.encrypt_file(input_file_path: str, output_file_path: str, password: str, kdf: str = 'argon2') None ¶
Encrypt a file using AES-GCM with a password-derived key.
Argon2id is used by default when available. Specify
kdf='scrypt'
orkdf='pbkdf2'
to maintain compatibility with existing files or when Argon2 support is missing.The file is processed in chunks to avoid loading the entire file into memory. The output file begins with the salt and nonce and ends with the authentication tag.
- async cryptography_suite.encrypt_file_async(input_file_path: str, output_file_path: str, password: str, kdf: str = 'argon2') None ¶
Asynchronously encrypt a file using AES-GCM with a password-derived key.
Requires the optional
aiofiles
package. The logic mirrorsencrypt_file()
but performs non-blocking I/O.
- cryptography_suite.from_pem(pem_str: str) RSAPrivateKey | EllipticCurvePrivateKey | Ed25519PrivateKey | Ed448PrivateKey | X25519PrivateKey | X448PrivateKey | RSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey | Ed448PublicKey | X25519PublicKey | X448PublicKey ¶
Load a key object from a PEM-formatted string.
- cryptography_suite.generate_aes_key(*, sensitive: bool = True) KeyVault | bytes ¶
Generates a secure random AES key.
When
sensitive
isTrue
(default) the key is wrapped in aKeyVault
so it can be reliably zeroized after use. Setsensitive=False
to obtain raw bytes without zeroization guarantees.
- cryptography_suite.generate_csr(common_name: str, private_key: RSAPrivateKey | EllipticCurvePrivateKey) bytes ¶
Generate a Certificate Signing Request (CSR).
- Parameters:
common_name (str) – The Common Name to include in the CSR.
private_key (RSAPrivateKey | EllipticCurvePrivateKey) – Private key used to sign the CSR.
- Returns:
The PEM-encoded CSR.
- Return type:
bytes
- cryptography_suite.generate_ec_keypair(curve=<cryptography.hazmat.primitives.asymmetric.ec.SECP256R1 object>) Tuple[EllipticCurvePrivateKey, EllipticCurvePublicKey] ¶
Generates an Elliptic Curve key pair.
- cryptography_suite.generate_ecdsa_keypair(curve: ~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve = <cryptography.hazmat.primitives.asymmetric.ec.SECP256R1 object>) Tuple[EllipticCurvePrivateKey, EllipticCurvePublicKey] ¶
Generates an ECDSA private and public key pair.
- cryptography_suite.generate_ed25519_keypair() Tuple[Ed25519PrivateKey, Ed25519PublicKey] ¶
Generates an Ed25519 private and public key pair.
- cryptography_suite.generate_hotp(secret: str, counter: int, digits: int = 6, algorithm: str = 'sha1') str ¶
Generates an HOTP code based on a shared secret and counter.
By default, this implementation uses SHA-1 for compatibility with existing standards (RFC 4226/RFC 6238). SHA-256 and SHA-512 are supported as alternatives via the
algorithm
parameter. For high-security use, prefer SHA-256 or higher if your authenticator supports it.
- cryptography_suite.generate_rsa_keypair(key_size: int = 4096) Tuple[RSAPrivateKey, RSAPublicKey] ¶
Generates an RSA private and public key pair.
- cryptography_suite.generate_rsa_keypair_async(key_size: int = 4096, *, executor: ThreadPoolExecutor | None = None, callback: Callable[[RSAPrivateKey, RSAPublicKey], None] | None = None) Future ¶
Generate an RSA key pair in a background thread.
The returned
Future
resolves to a tuple(private_key, public_key)
. Supplyingcallback
will invoke the callable with these arguments once generation completes. Ifexecutor
is omitted a temporaryThreadPoolExecutor
is created and shut down automatically.
- cryptography_suite.generate_salt(size: int = 16) bytes ¶
Generate a cryptographically secure random salt.
- cryptography_suite.generate_secure_random_string(length: int = 32) str ¶
Generates a secure random string using Base62 encoding.
- cryptography_suite.generate_totp(secret: str, interval: int = 30, digits: int = 6, algorithm: str = 'sha1', timestamp: int | None = None) str ¶
Generates a TOTP code based on a shared secret.
By default, this implementation uses SHA-1 for compatibility with existing standards (RFC 6238). SHA-256 and SHA-512 are supported as alternatives via the
algorithm
parameter. For high-security use, prefer SHA-256 or higher if your authenticator supports it.
- cryptography_suite.generate_x25519_keypair() Tuple[X25519PrivateKey, X25519PublicKey] ¶
Generates an X25519 private and public key pair.
- cryptography_suite.generate_x448_keypair() Tuple[X448PrivateKey, X448PublicKey] ¶
Generates an X448 private and public key pair.
- cryptography_suite.hybrid_decrypt(private_key: rsa.RSAPrivateKey | x25519.X25519PrivateKey, data: EncryptedHybridMessage | Mapping[str, str | bytes] | str | EncryptedMessage) bytes ¶
Decrypt data produced by
hybrid_encrypt()
.
- cryptography_suite.hybrid_encrypt(message: bytes, public_key: RSAPublicKey | X25519PublicKey, *, raw_output: bool = False) EncryptedHybridMessage ¶
Encrypt
message
using hybrid RSA/ECIES + AES-GCM.The AES key is randomly generated and encrypted with the recipient’s public key. The message itself is encrypted with AES-GCM.
- cryptography_suite.kdf_pbkdf2(password: str, salt: bytes, iterations: int, length: int) bytes ¶
Derive a key using PBKDF2-HMAC-SHA256 with configurable iterations.
- cryptography_suite.key_exists(filepath: str) bool ¶
Checks if a key file exists at the given filepath.
- cryptography_suite.load_certificate(pem_data: bytes) Certificate ¶
Load a PEM encoded certificate.
- Parameters:
pem_data (bytes) – The PEM-encoded certificate data.
- Returns:
Parsed certificate object.
- Return type:
cryptography.x509.Certificate
- cryptography_suite.load_ecdsa_private_key(pem_data: bytes, password: str) EllipticCurvePrivateKey ¶
Loads an ECDSA private key from PEM data.
- cryptography_suite.load_ecdsa_public_key(pem_data: bytes) EllipticCurvePublicKey ¶
Loads an ECDSA public key from PEM data.
- cryptography_suite.load_ed25519_private_key(pem_data: bytes, password: str) Ed25519PrivateKey ¶
Loads an Ed25519 private key from PEM data.
- cryptography_suite.load_ed25519_public_key(pem_data: bytes) Ed25519PublicKey ¶
Loads an Ed25519 public key from PEM data.
- cryptography_suite.load_private_key(pem_data: bytes, password: str)¶
Loads a private key (RSA, X25519, X448, or EC) from PEM data.
- cryptography_suite.load_private_key_from_file(filepath: str, password: str)¶
Loads a PEM-encoded private key from a file.
- cryptography_suite.load_public_key(pem_data: bytes)¶
Loads a public key (RSA, X25519, X448, or EC) from PEM data.
- cryptography_suite.load_public_key_from_file(filepath: str)¶
Loads a PEM-encoded public key from a file.
- cryptography_suite.pbkdf2_decrypt(encrypted_data: str, password: str) str ¶
- cryptography_suite.pbkdf2_encrypt(plaintext: str, password: str) str ¶
- cryptography_suite.pem_to_json(key: RSAPrivateKey | EllipticCurvePrivateKey | Ed25519PrivateKey | Ed448PrivateKey | X25519PrivateKey | X448PrivateKey | RSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey | Ed448PublicKey | X25519PublicKey | X448PublicKey) str ¶
Serialize a key to a JSON object containing a PEM string.
- cryptography_suite.reconstruct_secret(shares: List[Tuple[int, int]], prime: int = 6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151) int ¶
Reconstructs the secret from shares using Lagrange interpolation.
- cryptography_suite.rotate_aes_key(*, sensitive: bool = True) KeyVault | bytes ¶
Generates a new AES key to replace the old one.
- Parameters:
sensitive (bool, optional) – If
True
return the key wrapped inKeyVault
.
- cryptography_suite.scrypt_decrypt(encrypted_data: str, password: str) str ¶
- cryptography_suite.scrypt_encrypt(plaintext: str, password: str) str ¶
- cryptography_suite.secure_save_key_to_file(key_data: bytes, filepath: str)¶
Saves key data to a specified file path with secure permissions.
- cryptography_suite.secure_zero(data: bytearray) None ¶
Overwrite
data
with zeros in-place.Only mutable
bytearray
objects can be wiped in Python. Passing an immutablebytes
instance will raiseTypeError
and the original data may remain in memory until garbage collection. UseKeyVault
or convert tobytearray
before calling.
- cryptography_suite.select_backend(obj: Any) None ¶
Register and select a backend.
- Parameters:
obj – Either the name of a registered backend or a backend instance. When an instance is provided it will be registered under
obj.name
if the attribute exists, otherwise the lower-cased class name.
- cryptography_suite.self_sign_certificate(common_name: str, private_key: RSAPrivateKey | EllipticCurvePrivateKey, days_valid: int = 365) bytes ¶
Generate a self-signed X.509 certificate.
- Parameters:
common_name (str) – Common Name for the certificate.
private_key (RSAPrivateKey | EllipticCurvePrivateKey) – Private key to sign the certificate with.
days_valid (int, optional) – Number of days the certificate is valid for. Defaults to
365
.
- Returns:
The PEM-encoded certificate.
- Return type:
bytes
- cryptography_suite.serialize_ecdsa_private_key(private_key: EllipticCurvePrivateKey, password: str) bytes ¶
Serializes an ECDSA private key to PEM format with encryption.
- cryptography_suite.serialize_ecdsa_public_key(public_key: EllipticCurvePublicKey) bytes ¶
Serializes an ECDSA public key to PEM format.
- cryptography_suite.serialize_ed25519_private_key(private_key: Ed25519PrivateKey, password: str) bytes ¶
Serializes an Ed25519 private key to PEM format with encryption.
- cryptography_suite.serialize_ed25519_public_key(public_key: Ed25519PublicKey) bytes ¶
Serializes an Ed25519 public key to PEM format.
- cryptography_suite.serialize_private_key(private_key, password: str) bytes ¶
Serializes a private key to PEM format, encrypted with a password.
- cryptography_suite.serialize_public_key(public_key) bytes ¶
Serializes a public key to PEM format.
- cryptography_suite.set_audit_logger(logger: AuditLogger | None = None, *, log_file: str | None = None, key: bytes | None = None) None ¶
Configure the audit logger.
Passing
logger
sets a custom logger instance. Alternativelylog_file
andkey
can be provided to enable encrypted file logging. PassingNone
disables auditing.
- cryptography_suite.sha256_hash(data: str) str ¶
Generates a SHA-256 hash of the given data.
- cryptography_suite.sha384_hash(data: str) str ¶
Generates a SHA-384 hash of the given data.
- cryptography_suite.sha3_256_hash(data: str) str ¶
Generates a SHA3-256 hash of the given data.
- cryptography_suite.sha3_512_hash(data: str) str ¶
Generates a SHA3-512 hash of the given data.
- cryptography_suite.sha512_hash(data: str) str ¶
Generates a SHA-512 hash of the given data.
- cryptography_suite.sign_message(message: bytes, private_key: Ed25519PrivateKey, *, raw_output: bool = False) str | bytes ¶
Sign
message
using Ed25519 and return Base64 by default.
- cryptography_suite.sign_message_ecdsa(message: bytes, private_key: EllipticCurvePrivateKey, *, raw_output: bool = False) str | bytes ¶
Sign a message using ECDSA and return Base64 by default.
- cryptography_suite.to_pem(key: RSAPrivateKey | EllipticCurvePrivateKey | Ed25519PrivateKey | Ed448PrivateKey | X25519PrivateKey | X448PrivateKey | RSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey | Ed448PublicKey | X25519PublicKey | X448PublicKey) str ¶
Return a PEM-formatted string for a key.
- cryptography_suite.use_backend(name: str) _BackendContext ¶
Select the backend to use.
Backend selection is stored in a
contextvars.ContextVar
, making it safe for threads and asynchronous tasks. The function returns a context manager so it can be used inwith
blocks:with use_backend("pyca"): ...
Calling it without
with
permanently switches the backend for the current thread or task.
- cryptography_suite.verify_derived_key_pbkdf2(password: str, salt: bytes, expected_key: bytes) bool ¶
Verify a password against a previously derived PBKDF2 key.
- cryptography_suite.verify_derived_key_scrypt(password: str, salt: bytes, expected_key: bytes) bool ¶
Verify a password against an expected key using Scrypt.
- cryptography_suite.verify_hotp(code: str, secret: str, counter: int, digits: int = 6, window: int = 1, algorithm: str = 'sha1') bool ¶
Verifies an HOTP code within the allowed counter window.
By default, this implementation uses SHA-1 for compatibility with existing standards (RFC 4226/RFC 6238). SHA-256 and SHA-512 are supported as alternatives via the
algorithm
parameter. For high-security use, prefer SHA-256 or higher if your authenticator supports it.
- cryptography_suite.verify_signature(message: bytes, signature: bytes | str, public_key: Ed25519PublicKey) bool ¶
Verifies an Ed25519 signature.
- cryptography_suite.verify_signature_ecdsa(message: bytes, signature: bytes | str, public_key: EllipticCurvePublicKey) bool ¶
Verifies an ECDSA signature.
- cryptography_suite.verify_totp(code: str, secret: str, interval: int = 30, window: int = 1, digits: int = 6, algorithm: str = 'sha1', timestamp: int | None = None) bool ¶
Verifies a TOTP code within the allowed time window.
By default, this implementation uses SHA-1 for compatibility with existing standards (RFC 6238). SHA-256 and SHA-512 are supported as alternatives via the
algorithm
parameter. For high-security use, prefer SHA-256 or higher if your authenticator supports it.
- cryptography_suite.xchacha_decrypt(ciphertext: bytes | str, key: bytes, nonce: bytes | str) bytes ¶
Decrypt data encrypted with
xchacha_encrypt()
.
- cryptography_suite.xchacha_encrypt(message: bytes, key: bytes, nonce: bytes, *, raw_output: bool = False) dict ¶
Encrypt
message
using XChaCha20-Poly1305.
Experimental API¶
Legacy API¶
Legacy APIs for cryptography_suite
.
These helpers are retained for backward compatibility but are not part of the recommended public interface. Prefer alternatives in the core API for new code.
- cryptography_suite.legacy.blake3_hash_v2(data: str) str ¶
Another BLAKE3 hash helper used for testing.
- cryptography_suite.legacy.bls_aggregate(signatures: Iterable[bytes], *, raw_output: bool = False) str | bytes ¶
Aggregate multiple BLS signatures into one.
- Parameters:
signatures (Iterable[bytes]) – Individual signatures to aggregate.
- Returns:
Aggregated signature value.
- Return type:
bytes
- cryptography_suite.legacy.bls_aggregate_verify(public_keys: Sequence[bytes], messages: Sequence[bytes], signature: bytes | str) bool ¶
Verify an aggregated BLS signature against multiple messages.
- Parameters:
public_keys (Sequence[bytes]) – Public keys used to sign each message.
messages (Sequence[bytes]) – Messages that were individually signed.
signature (bytes) – Aggregated signature to verify.
- Returns:
True
if the aggregated signature is valid, otherwiseFalse
.- Return type:
bool
- cryptography_suite.legacy.bls_sign(message: bytes, private_key: int | bytes | bytearray | KeyVault, *, raw_output: bool = False) str | bytes ¶
Sign a message using the BLS signature scheme.
- Parameters:
message (bytes) – Message to sign.
private_key (int | bytes | KeyVault) – Private key generated via
generate_bls_keypair()
. It may be provided as aKeyVault
instance or raw integer/bytes.
- Returns:
Signature for
message
.- Return type:
bytes
- cryptography_suite.legacy.bls_verify(message: bytes, signature: bytes | str, public_key: bytes) bool ¶
Verify a BLS signature.
- Parameters:
message (bytes) – Signed message.
signature (bytes) – Signature to verify.
public_key (bytes) – Signer’s public key.
- Returns:
True
if the signature is valid, otherwiseFalse
.- Return type:
bool
- cryptography_suite.legacy.generate_bls_keypair(seed: bytes | None = None, *, sensitive: bool = True) Tuple[int | KeyVault, bytes] ¶
Generate a BLS12-381 key pair.
- Parameters:
seed (bytes | None, optional) – Optional 32-byte seed used as input key material. When
None
a cryptographically secure random seed is generated.sensitive (bool, optional) – If
True
(default) the private key is returned wrapped inKeyVault
for zeroization after use. Set toFalse
to receive the key as a Python integer.
- Returns:
The private key as either an integer or a
KeyVault
-wrapped byte string, and the corresponding public key.- Return type:
Tuple[Union[int, KeyVault], bytes]
- cryptography_suite.legacy.generate_ed448_keypair() Tuple[Ed448PrivateKey, Ed448PublicKey] ¶
Generates an Ed448 private and public key pair.
- cryptography_suite.legacy.sign_message_ed448(message: bytes, private_key: Ed448PrivateKey, *, raw_output: bool = False) str | bytes ¶
Sign a message using Ed448 and return Base64 by default.
- cryptography_suite.legacy.verify_signature_ed448(message: bytes, signature: bytes | str, public_key: Ed448PublicKey) bool ¶
Verifies an Ed448 signature.
Selecting a backend¶
>>> from cryptography_suite.crypto_backends import use_backend
>>> with use_backend("pyca"):
... pass
>>> with use_backend("sodium"):
... pass
>>> with use_backend("rust"):
... pass