spakky-cryptography¶
암호화 utility와 auth snapshot/password provider API입니다.
패키지 루트¶
Cryptography provider plugin public API.
AuthContextSnapshotVerificationResult(*, decision, auth_context=None)
dataclass
¶
CryptographyAuthProvider(config)
¶
Bases: IAuthContextSnapshotSigner, IAuthContextSnapshotVerifier, IPasswordHasher, IPasswordVerifier
Cryptography-backed provider for snapshot and password auth capabilities.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
sign_snapshot(request)
¶
Create a signed AuthContextSnapshot envelope.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
verify_snapshot(snapshot_envelope, invocation)
¶
Verify a signed snapshot envelope and return its AuthContext.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
verify_snapshot_result(snapshot_envelope, invocation)
¶
Verify a snapshot envelope and map auth errors to decisions.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
hash_password(password)
¶
Hash plaintext password material for storage.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
verify_password(password, password_hash)
¶
Verify plaintext password material against a retained password hash.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
CryptographyAuthProviderConfig()
¶
Bases: BaseSettings
Runtime config for cryptography auth provider capabilities.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
snapshot_key = Field(default_factory=(lambda: Key(size=32)))
class-attribute
instance-attribute
¶
HMAC key used to sign and verify AuthContextSnapshot envelopes.
snapshot_key_id = 'spakky-cryptography:default'
class-attribute
instance-attribute
¶
Identifier carried in signed snapshot envelopes.
snapshot_ttl = timedelta(minutes=5)
class-attribute
instance-attribute
¶
Validity window for newly signed snapshots.
clock = _utc_now
class-attribute
instance-attribute
¶
Clock used for signing and expiration validation.
verification_available = True
class-attribute
instance-attribute
¶
Whether snapshot verification provider dependencies are available.
password_available = True
class-attribute
instance-attribute
¶
Whether password hashing provider dependencies are available.
Aes(key, url_safe=False)
¶
Bases: ICryptor
AES-CBC encryption/decryption implementation.
Uses 256-bit keys (32 bytes) with automatic PKCS7 padding and random IV generation for each encryption operation.
Initialize AES encryptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
256-bit (32-byte) encryption key. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding for cipher text. |
False
|
Raises:
| Type | Description |
|---|---|
KeySizeError
|
If key is not 32 bytes. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/aes.py
encrypt(message)
¶
Encrypt a message using AES-CBC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Plain text message to encrypt. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encrypted cipher text in format "iv:cipher" (Base64 encoded). |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/aes.py
decrypt(cipher)
¶
Decrypt a cipher text using AES-CBC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cipher
|
str
|
Cipher text in format "iv:cipher" (Base64 encoded). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decrypted plain text message. |
Raises:
| Type | Description |
|---|---|
DecryptionFailedError
|
If decryption fails. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/aes.py
Gcm(key, url_safe=False)
¶
Bases: ICryptor
AES-GCM authenticated encryption/decryption implementation.
Uses 256-bit keys (32 bytes) with automatic PKCS7 padding, random IV, and AAD generation for authenticated encryption operations.
Initialize AES-GCM encryptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
256-bit (32-byte) encryption key. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding for cipher text. |
False
|
Raises:
| Type | Description |
|---|---|
KeySizeError
|
If key is not 32 bytes. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/gcm.py
encrypt(message)
¶
Encrypt a message using AES-GCM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Plain text message to encrypt. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encrypted cipher text in format "aad:tag:iv:cipher" (Base64 encoded). |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/gcm.py
decrypt(cipher)
¶
Decrypt a cipher text using AES-GCM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cipher
|
str
|
Cipher text in format "aad:tag:iv:cipher" (Base64 encoded). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decrypted plain text message. |
Raises:
| Type | Description |
|---|---|
DecryptionFailedError
|
If decryption or authentication fails. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/gcm.py
ICryptor
¶
Bases: ABC
Interface for encryption and decryption operations.
ISigner
¶
Bases: ABC
Interface for digital signature operations.
AsymmetricKey(key=None, size=None, passphrase=None)
¶
RSA asymmetric key pair.
Manages RSA public/private key pairs with support for key generation, import/export, and passphrase protection. Supports 1024, 2048, 4096, and 8192-bit keys.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
Rsa(key, url_safe=False)
¶
RSA encryption/decryption and signing/verification.
Provides PKCS1_OAEP encryption/decryption and PKCS1_v1_5 signing/verification using RSA asymmetric keys. Encryption uses the public key, decryption and signing require the private key.
Initialize RSA cryptor/signer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
AsymmetricKey
|
RSA asymmetric key pair. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding for cipher/signature. |
False
|
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
encrypt(message)
¶
Encrypt a message using RSA public key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Plain text message to encrypt. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encrypted cipher text (Base64 encoded). |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
decrypt(cipher)
¶
Decrypt a cipher text using RSA private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cipher
|
str
|
Cipher text to decrypt (Base64 encoded). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decrypted plain text message. |
Raises:
| Type | Description |
|---|---|
PrivateKeyRequiredError
|
If key pair has no private key. |
DecryptionFailedError
|
If decryption fails. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
sign(message, hash_type=HashType.SHA256)
¶
Sign a message using RSA private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Message to sign. |
required |
hash_type
|
HashType
|
Hash algorithm to use for signing. |
SHA256
|
Returns:
| Type | Description |
|---|---|
str
|
Digital signature (Base64 encoded). |
Raises:
| Type | Description |
|---|---|
PrivateKeyRequiredError
|
If key pair has no private key. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
verify(message, signature, hash_type=HashType.SHA256)
¶
Verify a signature using RSA public key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Original message that was signed. |
required |
signature
|
str
|
Digital signature to verify (Base64 encoded). |
required |
hash_type
|
HashType
|
Hash algorithm used for signing. |
SHA256
|
Returns:
| Type | Description |
|---|---|
bool
|
True if signature is valid, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
Base64Encoder
¶
Utility class for Base64 encoding and decoding operations.
encode(utf8, url_safe=False)
staticmethod
¶
Encode a UTF-8 string to Base64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
utf8
|
str
|
The string to encode. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding without padding. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The Base64-encoded string. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/encoding.py
decode(b64, url_safe=False)
staticmethod
¶
Decode a Base64 string to UTF-8.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b64
|
str
|
The Base64-encoded string to decode. |
required |
url_safe
|
bool
|
Use URL-safe Base64 decoding with padding restoration. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The decoded UTF-8 string. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/encoding.py
from_bytes(binary, url_safe=False)
staticmethod
¶
Encode binary data to Base64 string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary
|
bytes
|
The binary data to encode. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding without padding. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The Base64-encoded string. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/encoding.py
get_bytes(b64, url_safe=False)
staticmethod
¶
Decode a Base64 string to binary data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b64
|
str
|
The Base64-encoded string to decode. |
required |
url_safe
|
bool
|
Use URL-safe Base64 decoding with padding restoration. |
False
|
Returns:
| Type | Description |
|---|---|
bytes
|
The decoded binary data. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/encoding.py
Hash(data, hash_type=HashType.SHA256)
¶
Cryptographic hash computation utility.
Computes cryptographic hashes of strings or file streams using various hash algorithms. Supports multiple output formats including hex, Base64, and binary.
Initialize a hash computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | BufferedReader
|
The data to hash (string or file stream). |
required |
hash_type
|
HashType
|
The hash algorithm to use. |
SHA256
|
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/hash.py
hex
property
¶
Get hash as uppercase hexadecimal string.
b64
property
¶
Get hash as Base64-encoded string.
b64_urlsafe
property
¶
Get hash as URL-safe Base64-encoded string.
binary
property
¶
Get hash as binary data.
oid
property
¶
Get the OID (Object Identifier) of the hash algorithm.
digest()
¶
Compute and return the hash digest as binary data.
Returns:
| Type | Description |
|---|---|
bytes
|
The hash digest as bytes. |
HashType
¶
Bases: StrEnum
Supported cryptographic hash algorithms.
HMAC
¶
HMAC signing and verification utility.
Provides static methods for creating and verifying HMAC signatures using various hash algorithms.
sign_text(key, hmac_type, content, url_safe=False)
staticmethod
¶
Sign text content with HMAC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
The cryptographic key to use for signing. |
required |
hmac_type
|
HMACType
|
The HMAC hash algorithm to use. |
required |
content
|
str
|
The text content to sign. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding for the signature. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The HMAC signature as a Base64-encoded string. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/hmac_signer.py
verify(key, hmac_type, content, signature, url_safe=False)
staticmethod
¶
Verify HMAC signature of text content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
The cryptographic key used for verification. |
required |
hmac_type
|
HMACType
|
The HMAC hash algorithm to use. |
required |
content
|
str
|
The text content to verify. |
required |
signature
|
str
|
The expected HMAC signature as a Base64 string. |
required |
url_safe
|
bool
|
Whether the signature uses URL-safe Base64 encoding. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the signature is valid, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/hmac_signer.py
HMACType
¶
Bases: StrEnum
Supported HMAC hash algorithms.
Key(size=None, binary=None, base64=None, url_safe=False)
¶
Cryptographic key wrapper with format conversion utilities.
Supports creating keys from random generation, binary data, or Base64 encoding. Provides properties for converting keys to different formats.
Initialize a cryptographic key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int | None
|
Generate a random key of specified byte size. |
None
|
binary
|
bytes | None
|
Create key from binary data. |
None
|
base64
|
str | None
|
Create key from Base64-encoded string. |
None
|
url_safe
|
bool
|
Use URL-safe Base64 decoding when base64 is provided. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no valid initialization method is provided. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/key.py
Argon2PasswordEncoder(*, password_hash=None, password=None, salt=None, time_cost=3, memory_cost=65536, parallelism=4, hash_len=32, url_safe=False)
¶
Bases: IPasswordEncoder
Argon2 password encoder.
Uses the Argon2 key derivation function for secure password hashing with configurable computational complexity parameters.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/argon2.py
encode()
¶
Encode password hash as a string.
Returns:
| Type | Description |
|---|---|
str
|
Encoded password hash string with algorithm and parameters. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/argon2.py
challenge(password)
¶
Verify a password against the stored hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
Password to verify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if password matches, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/argon2.py
BcryptPasswordEncoder(password_hash=None, password=None, url_safe=False, rounds=None)
¶
Bases: IPasswordEncoder
Bcrypt password encoder.
Uses the Bcrypt adaptive hash function for secure password hashing with automatic salt generation.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/bcrypt.py
encode()
¶
Encode password hash as a string.
Returns:
| Type | Description |
|---|---|
str
|
Encoded password hash string with algorithm and salt. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/bcrypt.py
challenge(password)
¶
Verify a password against the stored hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
Password to verify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if password matches, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/bcrypt.py
IPasswordEncoder
¶
Pbkdf2PasswordEncoder(*, password_hash=None, password=None, salt=None, hash_type=HashType.SHA256, iteration=100000, url_safe=False)
¶
Bases: IPasswordEncoder
PBKDF2 password encoder.
Uses the PBKDF2 key derivation function for secure password hashing with configurable iteration count and hash algorithm.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/pbkdf2.py
encode()
¶
Encode password hash as a string.
Returns:
| Type | Description |
|---|---|
str
|
Encoded password hash string with algorithm, hash type, and parameters. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/pbkdf2.py
challenge(password)
¶
Verify a password against the stored hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
Password to verify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if password matches, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/pbkdf2.py
ScryptPasswordEncoder(*, password_hash=None, password=None, salt=None, n=2 ** 14, r=8, p=1, maxmem=0, dklen=32, url_safe=False)
¶
Bases: IPasswordEncoder
Scrypt password encoder.
Uses the Scrypt key derivation function for secure password hashing with configurable CPU/memory cost parameters for enhanced security.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/scrypt.py
encode()
¶
Encode password hash as a string.
Returns:
| Type | Description |
|---|---|
str
|
Encoded password hash string with algorithm and parameters. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/scrypt.py
challenge(password)
¶
Verify a password against the stored hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
Password to verify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if password matches, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/scrypt.py
플러그인 진입점¶
Plugin initialization for cryptography utilities and auth provider.
initialize(app)
¶
Register cryptography config, auth provider, and auth port bindings.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/main.py
Auth Provider¶
Auth snapshot and password capabilities backed by cryptographic utilities.
CRYPTOGRAPHY_AUTH_PROVIDER_ID = 'provider:spakky-cryptography'
module-attribute
¶
Stable auth provider id advertised by spakky-cryptography.
SNAPSHOT_SIGNATURE_ALGORITHM = 'HS256'
module-attribute
¶
Snapshot envelope signature algorithm used by this provider.
CryptographyAuthProviderConfig()
¶
Bases: BaseSettings
Runtime config for cryptography auth provider capabilities.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
snapshot_key = Field(default_factory=(lambda: Key(size=32)))
class-attribute
instance-attribute
¶
HMAC key used to sign and verify AuthContextSnapshot envelopes.
snapshot_key_id = 'spakky-cryptography:default'
class-attribute
instance-attribute
¶
Identifier carried in signed snapshot envelopes.
snapshot_ttl = timedelta(minutes=5)
class-attribute
instance-attribute
¶
Validity window for newly signed snapshots.
clock = _utc_now
class-attribute
instance-attribute
¶
Clock used for signing and expiration validation.
verification_available = True
class-attribute
instance-attribute
¶
Whether snapshot verification provider dependencies are available.
password_available = True
class-attribute
instance-attribute
¶
Whether password hashing provider dependencies are available.
AuthContextSnapshotVerificationResult(*, decision, auth_context=None)
dataclass
¶
CryptographyAuthProvider(config)
¶
Bases: IAuthContextSnapshotSigner, IAuthContextSnapshotVerifier, IPasswordHasher, IPasswordVerifier
Cryptography-backed provider for snapshot and password auth capabilities.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
sign_snapshot(request)
¶
Create a signed AuthContextSnapshot envelope.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
verify_snapshot(snapshot_envelope, invocation)
¶
Verify a signed snapshot envelope and return its AuthContext.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
verify_snapshot_result(snapshot_envelope, invocation)
¶
Verify a snapshot envelope and map auth errors to decisions.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
hash_password(password)
¶
Hash plaintext password material for storage.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
verify_password(password, password_hash)
¶
Verify plaintext password material against a retained password hash.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
cryptography_auth_provider_contribution()
¶
Return the auth capabilities contributed by spakky-cryptography.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/auth_provider.py
Key / Encoding / Hash / HMAC¶
Cryptographic key management utilities.
Provides utilities for generating, storing, and converting cryptographic keys in various formats including binary, Base64, and hexadecimal.
Key(size=None, binary=None, base64=None, url_safe=False)
¶
Cryptographic key wrapper with format conversion utilities.
Supports creating keys from random generation, binary data, or Base64 encoding. Provides properties for converting keys to different formats.
Initialize a cryptographic key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int | None
|
Generate a random key of specified byte size. |
None
|
binary
|
bytes | None
|
Create key from binary data. |
None
|
base64
|
str | None
|
Create key from Base64-encoded string. |
None
|
url_safe
|
bool
|
Use URL-safe Base64 decoding when base64 is provided. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no valid initialization method is provided. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/key.py
Base64 encoding and decoding utilities.
Provides utilities for encoding and decoding data in Base64 format with support for URL-safe encoding and direct bytes conversion.
Base64Encoder
¶
Utility class for Base64 encoding and decoding operations.
encode(utf8, url_safe=False)
staticmethod
¶
Encode a UTF-8 string to Base64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
utf8
|
str
|
The string to encode. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding without padding. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The Base64-encoded string. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/encoding.py
decode(b64, url_safe=False)
staticmethod
¶
Decode a Base64 string to UTF-8.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b64
|
str
|
The Base64-encoded string to decode. |
required |
url_safe
|
bool
|
Use URL-safe Base64 decoding with padding restoration. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The decoded UTF-8 string. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/encoding.py
from_bytes(binary, url_safe=False)
staticmethod
¶
Encode binary data to Base64 string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary
|
bytes
|
The binary data to encode. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding without padding. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The Base64-encoded string. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/encoding.py
get_bytes(b64, url_safe=False)
staticmethod
¶
Decode a Base64 string to binary data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b64
|
str
|
The Base64-encoded string to decode. |
required |
url_safe
|
bool
|
Use URL-safe Base64 decoding with padding restoration. |
False
|
Returns:
| Type | Description |
|---|---|
bytes
|
The decoded binary data. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/encoding.py
Cryptographic hash utilities.
Provides utilities for computing cryptographic hashes using various algorithms including MD5, SHA1, SHA224, SHA256, SHA384, and SHA512.
HashType
¶
Bases: StrEnum
Supported cryptographic hash algorithms.
Hash(data, hash_type=HashType.SHA256)
¶
Cryptographic hash computation utility.
Computes cryptographic hashes of strings or file streams using various hash algorithms. Supports multiple output formats including hex, Base64, and binary.
Initialize a hash computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | BufferedReader
|
The data to hash (string or file stream). |
required |
hash_type
|
HashType
|
The hash algorithm to use. |
SHA256
|
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/hash.py
hex
property
¶
Get hash as uppercase hexadecimal string.
b64
property
¶
Get hash as Base64-encoded string.
b64_urlsafe
property
¶
Get hash as URL-safe Base64-encoded string.
binary
property
¶
Get hash as binary data.
oid
property
¶
Get the OID (Object Identifier) of the hash algorithm.
digest()
¶
Compute and return the hash digest as binary data.
Returns:
| Type | Description |
|---|---|
bytes
|
The hash digest as bytes. |
HMAC signing and verification utilities.
Provides utilities for creating and verifying HMAC signatures using various hash algorithms (SHA-224, SHA-256, SHA-384, SHA-512).
HMACType
¶
Bases: StrEnum
Supported HMAC hash algorithms.
HMAC
¶
HMAC signing and verification utility.
Provides static methods for creating and verifying HMAC signatures using various hash algorithms.
sign_text(key, hmac_type, content, url_safe=False)
staticmethod
¶
Sign text content with HMAC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
The cryptographic key to use for signing. |
required |
hmac_type
|
HMACType
|
The HMAC hash algorithm to use. |
required |
content
|
str
|
The text content to sign. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding for the signature. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The HMAC signature as a Base64-encoded string. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/hmac_signer.py
verify(key, hmac_type, content, signature, url_safe=False)
staticmethod
¶
Verify HMAC signature of text content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
The cryptographic key used for verification. |
required |
hmac_type
|
HMACType
|
The HMAC hash algorithm to use. |
required |
content
|
str
|
The text content to verify. |
required |
signature
|
str
|
The expected HMAC signature as a Base64 string. |
required |
url_safe
|
bool
|
Whether the signature uses URL-safe Base64 encoding. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the signature is valid, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/hmac_signer.py
Symmetric / Asymmetric Cryptography¶
Cryptography protocol interfaces.
Defines protocol interfaces for encryption/decryption and signing/verification operations used by cryptographic implementations.
AES encryption and decryption utilities.
Provides AES-CBC mode encryption/decryption with automatic padding and IV generation using 256-bit keys.
Aes(key, url_safe=False)
¶
Bases: ICryptor
AES-CBC encryption/decryption implementation.
Uses 256-bit keys (32 bytes) with automatic PKCS7 padding and random IV generation for each encryption operation.
Initialize AES encryptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
256-bit (32-byte) encryption key. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding for cipher text. |
False
|
Raises:
| Type | Description |
|---|---|
KeySizeError
|
If key is not 32 bytes. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/aes.py
encrypt(message)
¶
Encrypt a message using AES-CBC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Plain text message to encrypt. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encrypted cipher text in format "iv:cipher" (Base64 encoded). |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/aes.py
decrypt(cipher)
¶
Decrypt a cipher text using AES-CBC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cipher
|
str
|
Cipher text in format "iv:cipher" (Base64 encoded). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decrypted plain text message. |
Raises:
| Type | Description |
|---|---|
DecryptionFailedError
|
If decryption fails. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/aes.py
AES-GCM encryption and decryption utilities.
Provides AES-GCM mode authenticated encryption/decryption with automatic padding, IV, and AAD generation using 256-bit keys.
Gcm(key, url_safe=False)
¶
Bases: ICryptor
AES-GCM authenticated encryption/decryption implementation.
Uses 256-bit keys (32 bytes) with automatic PKCS7 padding, random IV, and AAD generation for authenticated encryption operations.
Initialize AES-GCM encryptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
256-bit (32-byte) encryption key. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding for cipher text. |
False
|
Raises:
| Type | Description |
|---|---|
KeySizeError
|
If key is not 32 bytes. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/gcm.py
encrypt(message)
¶
Encrypt a message using AES-GCM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Plain text message to encrypt. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encrypted cipher text in format "aad:tag:iv:cipher" (Base64 encoded). |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/gcm.py
decrypt(cipher)
¶
Decrypt a cipher text using AES-GCM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cipher
|
str
|
Cipher text in format "aad:tag:iv:cipher" (Base64 encoded). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decrypted plain text message. |
Raises:
| Type | Description |
|---|---|
DecryptionFailedError
|
If decryption or authentication fails. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/gcm.py
RSA encryption, decryption, and signing utilities.
Provides RSA asymmetric cryptography operations including key generation, encryption/decryption with PKCS1_OAEP, and signing/verification with PKCS1_v1_5.
AsymmetricKey(key=None, size=None, passphrase=None)
¶
RSA asymmetric key pair.
Manages RSA public/private key pairs with support for key generation, import/export, and passphrase protection. Supports 1024, 2048, 4096, and 8192-bit keys.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
Rsa(key, url_safe=False)
¶
RSA encryption/decryption and signing/verification.
Provides PKCS1_OAEP encryption/decryption and PKCS1_v1_5 signing/verification using RSA asymmetric keys. Encryption uses the public key, decryption and signing require the private key.
Initialize RSA cryptor/signer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
AsymmetricKey
|
RSA asymmetric key pair. |
required |
url_safe
|
bool
|
Use URL-safe Base64 encoding for cipher/signature. |
False
|
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
encrypt(message)
¶
Encrypt a message using RSA public key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Plain text message to encrypt. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encrypted cipher text (Base64 encoded). |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
decrypt(cipher)
¶
Decrypt a cipher text using RSA private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cipher
|
str
|
Cipher text to decrypt (Base64 encoded). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decrypted plain text message. |
Raises:
| Type | Description |
|---|---|
PrivateKeyRequiredError
|
If key pair has no private key. |
DecryptionFailedError
|
If decryption fails. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
sign(message, hash_type=HashType.SHA256)
¶
Sign a message using RSA private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Message to sign. |
required |
hash_type
|
HashType
|
Hash algorithm to use for signing. |
SHA256
|
Returns:
| Type | Description |
|---|---|
str
|
Digital signature (Base64 encoded). |
Raises:
| Type | Description |
|---|---|
PrivateKeyRequiredError
|
If key pair has no private key. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
verify(message, signature, hash_type=HashType.SHA256)
¶
Verify a signature using RSA public key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Original message that was signed. |
required |
signature
|
str
|
Digital signature to verify (Base64 encoded). |
required |
hash_type
|
HashType
|
Hash algorithm used for signing. |
SHA256
|
Returns:
| Type | Description |
|---|---|
bool
|
True if signature is valid, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/cryptography/rsa.py
Password Encoders¶
Password encoding protocol interface.
Defines the protocol interface for password hashing implementations used by various password encoding algorithms.
IPasswordEncoder
¶
Argon2 password hashing implementation.
Provides password hashing using the Argon2 algorithm with configurable parameters for time cost, memory cost, parallelism, and hash length.
Argon2PasswordEncoder(*, password_hash=None, password=None, salt=None, time_cost=3, memory_cost=65536, parallelism=4, hash_len=32, url_safe=False)
¶
Bases: IPasswordEncoder
Argon2 password encoder.
Uses the Argon2 key derivation function for secure password hashing with configurable computational complexity parameters.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/argon2.py
encode()
¶
Encode password hash as a string.
Returns:
| Type | Description |
|---|---|
str
|
Encoded password hash string with algorithm and parameters. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/argon2.py
challenge(password)
¶
Verify a password against the stored hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
Password to verify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if password matches, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/argon2.py
Bcrypt password hashing implementation.
Provides password hashing using the Bcrypt algorithm with automatic salt generation and configurable work factor.
BcryptPasswordEncoder(password_hash=None, password=None, url_safe=False, rounds=None)
¶
Bases: IPasswordEncoder
Bcrypt password encoder.
Uses the Bcrypt adaptive hash function for secure password hashing with automatic salt generation.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/bcrypt.py
encode()
¶
Encode password hash as a string.
Returns:
| Type | Description |
|---|---|
str
|
Encoded password hash string with algorithm and salt. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/bcrypt.py
challenge(password)
¶
Verify a password against the stored hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
Password to verify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if password matches, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/bcrypt.py
PBKDF2 password hashing implementation.
Provides password hashing using the PBKDF2 key derivation function with configurable hash algorithm, iteration count, and salt.
Pbkdf2PasswordEncoder(*, password_hash=None, password=None, salt=None, hash_type=HashType.SHA256, iteration=100000, url_safe=False)
¶
Bases: IPasswordEncoder
PBKDF2 password encoder.
Uses the PBKDF2 key derivation function for secure password hashing with configurable iteration count and hash algorithm.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/pbkdf2.py
encode()
¶
Encode password hash as a string.
Returns:
| Type | Description |
|---|---|
str
|
Encoded password hash string with algorithm, hash type, and parameters. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/pbkdf2.py
challenge(password)
¶
Verify a password against the stored hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
Password to verify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if password matches, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/pbkdf2.py
Scrypt password hashing implementation.
Provides password hashing using the Scrypt key derivation function with configurable CPU and memory cost parameters for resistance against hardware brute-force attacks.
ScryptPasswordEncoder(*, password_hash=None, password=None, salt=None, n=2 ** 14, r=8, p=1, maxmem=0, dklen=32, url_safe=False)
¶
Bases: IPasswordEncoder
Scrypt password encoder.
Uses the Scrypt key derivation function for secure password hashing with configurable CPU/memory cost parameters for enhanced security.
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/scrypt.py
encode()
¶
Encode password hash as a string.
Returns:
| Type | Description |
|---|---|
str
|
Encoded password hash string with algorithm and parameters. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/scrypt.py
challenge(password)
¶
Verify a password against the stored hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
Password to verify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if password matches, False otherwise. |
Source code in plugins/spakky-cryptography/src/spakky/plugins/cryptography/password/scrypt.py
Errors¶
Cryptography-related error classes.
Provides specialized exception classes for cryptography and key management.
DecryptionFailedError
¶
Bases: AbstractSpakkyFrameworkError
Raised when decryption fails due to invalid key or corrupted data.
KeySizeError
¶
PrivateKeyRequiredError
¶
CannotImportAsymmetricKeyError
¶
InvalidKeyConstructorCallError
¶
IncompatibleKeyTypeError
¶
PasswordRequiredError
¶
AsymmetricKeyRequiredError
¶
추가 모듈¶
Auth feature contribution for the cryptography provider.
initialize(app)
¶
Register cryptography auth capability metadata.