Cryptographic utilities — hashing, symmetric/asymmetric encryption, KDF.
Submodules
This module is a facade that delegates to specialized submodules:
Apero.Crypto.Hash— SHA-256, SHA-512, MD5, HMACApero.Crypto.Cipher— AES-256-GCM, ChaCha20-Poly1305, AES-256-CTR streamingApero.Crypto.Key— PBKDF2, Argon2id, ECDH, RSA key generationApero.Crypto.Random— key generation, random hex/token/password, secure_compare
Deprecation
All functions in this module are deprecated in favor of the submodules.
Use Apero.Crypto.Hash, Apero.Crypto.Cipher, Apero.Crypto.Key, and
Apero.Crypto.Random directly.
All keys and IVs use :crypto.strong_rand_bytes/1. Encrypted values are
self-contained (IV/nonce + tag + ciphertext, Base64-encoded).
Summary
Functions
Derives a key using Argon2id (requires optional argon2_elixir dependency).
Computes a shared secret from your private key and peer's public key.
Decrypts a value encrypted with encrypt/2. Returns {:ok, plaintext} or {:error, reason}.
Decrypts ChaCha20-Poly1305 encrypted data.
Decrypts data encrypted with AES-256-CTR streaming.
Encrypts plaintext with AES-256-GCM. Returns {:ok, ciphertext}.
Encrypts plaintext with ChaCha20-Poly1305.
Generates an X25519 key pair. Returns {private_key, public_key} (both raw binary).
Generates a random 256-bit key.
Generates an RSA key pair (2048-bit). Returns {private_der, public_der}.
HMAC-SHA256 (hex encoded).
MD5 hash (hex encoded). NOTE: MD5 is cryptographically broken — only for checksums.
Derives a key using PBKDF2-HMAC-SHA256.
Generates a random hex string.
Generates a random password with configurable length and character sets.
Generates a random URL-safe token.
Timing-safe string comparison.
SHA-256 hash (hex encoded).
SHA-512 hash (hex encoded).
Encrypts a chunk of data in streaming mode.
Finalizes a streaming encryption. Returns the final state (discard after).
Starts an AES-256-CTR encryption stream. Use with stream_encrypt/2 and stream_finalize/1.
Functions
Derives a key using Argon2id (requires optional argon2_elixir dependency).
Computes a shared secret from your private key and peer's public key.
Decrypts a value encrypted with encrypt/2. Returns {:ok, plaintext} or {:error, reason}.
Decrypts ChaCha20-Poly1305 encrypted data.
Decrypts data encrypted with AES-256-CTR streaming.
Encrypts plaintext with AES-256-GCM. Returns {:ok, ciphertext}.
Encrypts plaintext with ChaCha20-Poly1305.
Generates an X25519 key pair. Returns {private_key, public_key} (both raw binary).
@spec generate_key() :: binary()
Generates a random 256-bit key.
Generates an RSA key pair (2048-bit). Returns {private_der, public_der}.
HMAC-SHA256 (hex encoded).
MD5 hash (hex encoded). NOTE: MD5 is cryptographically broken — only for checksums.
Derives a key using PBKDF2-HMAC-SHA256.
@spec random_hex(non_neg_integer()) :: binary()
Generates a random hex string.
@spec random_password( non_neg_integer(), keyword() ) :: binary()
Generates a random password with configurable length and character sets.
@spec random_token(non_neg_integer()) :: binary()
Generates a random URL-safe token.
Timing-safe string comparison.
SHA-256 hash (hex encoded).
SHA-512 hash (hex encoded).
Encrypts a chunk of data in streaming mode.
Finalizes a streaming encryption. Returns the final state (discard after).
Starts an AES-256-CTR encryption stream. Use with stream_encrypt/2 and stream_finalize/1.