wauth.core module

Cryptographic engine for encrypting and decrypting data using Fernet.

class wauth.core.CryptoEngine(custom_key=None)[source]

Bases: object

Handles encryption and decryption using Fernet (AES-128-CBC).

The encryption key is derived from a machine-specific identifier, meaning data encrypted on one machine can only be decrypted on that same machine.

Parameters:

custom_key (str | None) – Optional custom encryption key string. If provided, it is hashed with SHA-256 to produce a deterministic 32-byte key. If None, the key is derived from the machine identifier.

__init__(custom_key=None)[source]
encrypt(data)[source]

Encrypt raw bytes into a Fernet token.

Parameters:

data (bytes) – Plaintext data to encrypt.

Returns:

Base64-encoded Fernet token as a string.

Return type:

str

decrypt(token)[source]

Decrypt a Fernet token back to raw bytes.

Parameters:

token (str) – Base64-encoded Fernet token.

Returns:

Decrypted plaintext as bytes.

Raises:

DecryptionError – If the token is invalid, tampered, or encrypted with a different key.

Return type:

bytes