transparentmeta.crypto package
Submodules
transparentmeta.crypto.character_encoding module
This module defines the CharacterEncoding enumeration, which provides standard character encoding options for string-to-byte conversions.
transparentmeta.crypto.exceptions module
This module hosts all custom exceptions used in the crypto parckage.
transparentmeta.crypto.hasher module
This module provides a simple wrapper around Python’s hashlib library to compute cryptographic hash digests using various algorithms such as SHA-256, SHA-512, and MD5.
- class transparentmeta.crypto.hasher.Hasher(hash_algorithm_name='sha256')[source]
Bases:
objectA utility class for computing hash digests using various cryptographic algorithms.
- hash_algorithm_name
The name of the hashing algorithm (e.g., “sha256”).
- Type:
str
transparentmeta.crypto.key_management module
Ed25519 Key Management Module
This module provides functions for generating, storing, loading, and converting Ed25519 cryptographic key pairs. These keys are used for digital signatures and secure communications. User A can sign a message with their private key, and User B can verify the signature using User A’s public key.
- Functions:
- generate_key_pair() -> tuple:
Generates a new Ed25519 private and public key pair.
- save_private_key_to_pem_file(private_key, filepath) -> None:
Saves a private key to a PEM file.
- save_public_key_to_pem_file(public_key, filepath) -> None:
Saves a public key to a PEM file.
- load_private_key_from_pem_file(filepath) -> ed25519.Ed25519PrivateKey:
Loads a private key from a PEM file.
- load_public_key_from_pem_file(filepath) -> ed25519.Ed25519PublicKey:
Loads a public key from a PEM file.
- convert_private_key_to_hex(private_key) -> str:
Converts a private key to a hex string.
- convert_public_key_to_hex(public_key) -> str:
Converts a public key to a hex string.
- load_private_key_from_hex_string(hex_string) -> ed25519.Ed25519PrivateKey:
Converts a hex-encoded private key back to an Ed25519PrivateKey object.
- load_public_key_from_hex_string(hex_string) -> ed25519.Ed25519PublicKey:
Converts a hex-encoded public key back to an Ed25519PublicKey object.
- transparentmeta.crypto.key_management.convert_private_key_to_hex(private_key)[source]
Converts a private key to a hex-encoded string.
- Parameters:
private_key (ed25519.Ed25519PrivateKey) – The private key to convert.
- Returns:
The hex-encoded private key.
- Return type:
hexadecimal_encoded_private_key (str)
- transparentmeta.crypto.key_management.convert_public_key_to_hex(public_key)[source]
Converts a public key to a hex-encoded string.
- Parameters:
public_key (ed25519.Ed25519PublicKey) – The public key to convert.
- Returns:
The hex-encoded public key.
- Return type:
hexadecimal_encoded_public_key (str)
- transparentmeta.crypto.key_management.generate_key_pair()[source]
Generates a new Ed25519 private and public key pair.
- Returns:
A tuple containing an Ed25519PrivateKey and Ed25519PublicKey.
- Return type:
tuple
- transparentmeta.crypto.key_management.load_private_key_from_hex_string(hex_encoded_private_key)[source]
Converts a hex-encoded private key back to an Ed25519PrivateKey object.
- Parameters:
hex_string (str) – The hex-encoded private key.
- Returns:
- The decoded private key
object.
- Return type:
private_key (ed25519.Ed25519PrivateKey)
- transparentmeta.crypto.key_management.load_private_key_from_pem_file(filepath)[source]
Loads a private key from a PEM file and ensures it is Ed25519.
- Parameters:
filepath (Path) – The Path object of the private key to load.
- Returns:
The loaded private key object.
- Return type:
ed25519.Ed25519PrivateKey
- Raises:
NotEd25519KeyError – If the loaded key is not an Ed25519 private key.
- transparentmeta.crypto.key_management.load_public_key_from_hex_string(hex_encoded_public_key)[source]
Converts a hex-encoded public key back to an Ed25519PublicKey object.
- Parameters:
hex_encoded_public_key (str) – The hex-encoded public key.
- Returns:
The decoded public key object.
- Return type:
public_key (ed25519.Ed25519PublicKey)
- transparentmeta.crypto.key_management.load_public_key_from_pem_file(filepath)[source]
Loads a public key from a PEM file and ensures it is Ed25519.
- Parameters:
filepath (Path) – The Path object of the public key to load.
- Returns:
The loaded public key object.
- Return type:
ed25519.Ed25519PublicKey
- Raises:
NotEd25519KeyError – If the loaded key is not an Ed25519 public key.
- transparentmeta.crypto.key_management.save_private_key_to_pem_file(private_key, filepath)[source]
Saves a private key to a PEM file.
- Parameters:
private_key (ed25519.Ed25519PrivateKey) – The private key to save.
filepath (Path) – The Path object where the private key should be saved.
- Return type:
None
transparentmeta.crypto.signature_verifier module
This module provides a SignatureVerifier class that enables verifying messages signed with the Ed25519 cryptographic algorithm. It supports different character encodings for message conversion before verification.
- class transparentmeta.crypto.signature_verifier.SignatureVerifier(public_key, character_encoding=CharacterEncoding.UTF8)[source]
Bases:
objectA utility class for verifying Ed25519 digital signatures.
- public_key
The public key used for verifying signatures.
- Type:
ed25519.Ed25519PublicKey
- character_encoding
The encoding used for converting strings to bytes before verification.
- Type:
- __init__(public_key, character_encoding=CharacterEncoding.UTF8)[source]
Initializes the verifier with a public key and a character encoding.
- Parameters:
public_key (ed25519.Ed25519PublicKey) – The public key for verifying signatures.
character_encoding (CharacterEncoding) – The encoding used for converting strings to bytes before verification.
- is_signature_valid(message, signature)[source]
Verifies an Ed25519 hex-encoded signature for a given message.
- Parameters:
message (str) – The original message that was signed.
signature (str) – The hex-encoded digital signature.
- Returns:
True if the signature is valid, False otherwise.
- Return type:
bool
transparentmeta.crypto.signer module
This module provides a Signer class that enables signing messages using the Ed25519 cryptographic algorithm. It supports different character encodings for message conversion before signing.
- class transparentmeta.crypto.signer.Signer(private_key, character_encoding=CharacterEncoding.UTF8)[source]
Bases:
objectA utility class for digitally signing messages using the Ed25519 cryptographic algorithm.
- private_key
The private key used for signing messages.
- Type:
ed25519.Ed25519PrivateKey
- character_encoding
The encoding used for converting strings to bytes before signing.
- Type:
- __init__(private_key, character_encoding=CharacterEncoding.UTF8)[source]
Initializes the signer with a private key and a character encoding.
- Parameters:
private_key (ed25519.Ed25519PrivateKey) – The private key for signing messages.
character_encoding (CharacterEncoding) – The encoding used for converting strings to bytes before signing.