Skip to content

Crypto Module

The rite.crypto package provides hashing, HMAC, UUID, and other cryptographic helpers built entirely on the Python standard library.

Overview

This section introduces the cryptographic helpers at a high level. Each submodule page contains the detailed API reference.

Submodules

  • Hash: Cryptographic hash functions.
  • UUID: Generate and validate UUIDs.
  • Random: Cryptographically secure random generation.
  • Cipher: Classical cipher implementations.

Examples

Hashing

from rite.crypto import hash_sha256, hash_blake2b

# SHA-256 hash
data = "sensitive data"
hashed = hash_sha256(data)

# BLAKE2b hash
hashed_b = hash_blake2b(data.encode())

UUID Operations

from rite.crypto import (
    uuid_random,
    uuid_hex,
    uuid_is_valid,
    uuid_from_name
)

# Generate random UUID
random_id = uuid_random()

# Get hex representation
hex_id = uuid_hex(random_id)

# Validate UUID
is_valid = uuid_is_valid(hex_id)

# Generate UUID from name
namespace_uuid = uuid_random()
name_uuid = uuid_from_name(namespace_uuid, "example.com")

Secure Random Generation

from rite.crypto import random_bytes, random_hex, random_int

# Generate random bytes
secret_key = random_bytes(32)

# Generate random hex string
token = random_hex(16)

# Generate random integer
nonce = random_int(0, 1000000)