Apero.Crypto (Apero v3.0.0)

Copy Markdown View Source

Cryptographic utilities — hashing, symmetric/asymmetric encryption, KDF.

Submodules

This module is a facade that delegates to specialized submodules:

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).

generate_key() deprecated

Generates a random 256-bit key.

Generates an RSA key pair (2048-bit). Returns {private_der, public_der}.

hmac(secret, data) deprecated

HMAC-SHA256 (hex encoded).

md5(data) deprecated

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.

sha256(data) deprecated

SHA-256 hash (hex encoded).

sha512(data) deprecated

SHA-512 hash (hex encoded).

Encrypts a chunk of data in streaming mode.

Finalizes a streaming encryption. Returns the final state (discard after).

stream_init(key) deprecated

Starts an AES-256-CTR encryption stream. Use with stream_encrypt/2 and stream_finalize/1.

Functions

argon2id(password, salt, opts \\ [])

This function is deprecated. Use Apero.Crypto.Key.argon2id/3 instead.
@spec argon2id(binary(), binary(), keyword()) :: {:ok, binary()} | {:error, term()}

Derives a key using Argon2id (requires optional argon2_elixir dependency).

compute_ecdh_secret(my_private, peer_public)

This function is deprecated. Use Apero.Crypto.Key.compute_ecdh_secret/2 instead.
@spec compute_ecdh_secret(binary(), binary()) :: {:ok, binary()} | :error

Computes a shared secret from your private key and peer's public key.

decrypt(encoded, key)

This function is deprecated. Use Apero.Crypto.Cipher.decrypt/2 instead.
@spec decrypt(binary(), binary()) :: {:ok, binary()} | {:error, term()}

Decrypts a value encrypted with encrypt/2. Returns {:ok, plaintext} or {:error, reason}.

decrypt_chacha20(encoded, key)

This function is deprecated. Use Apero.Crypto.Cipher.decrypt_chacha20/2 instead.
@spec decrypt_chacha20(binary(), binary()) :: {:ok, binary()} | :error

Decrypts ChaCha20-Poly1305 encrypted data.

decrypt_ctr(ciphertext, key, iv)

This function is deprecated. Use Apero.Crypto.Cipher.decrypt_ctr/3 instead.
@spec decrypt_ctr(binary(), binary(), binary()) :: {:ok, binary()} | :error

Decrypts data encrypted with AES-256-CTR streaming.

encrypt(plaintext, key \\ nil)

This function is deprecated. Use Apero.Crypto.Cipher.encrypt/2 instead.
@spec encrypt(binary(), binary() | nil) :: {:ok, binary()}

Encrypts plaintext with AES-256-GCM. Returns {:ok, ciphertext}.

encrypt_chacha20(plaintext, key)

This function is deprecated. Use Apero.Crypto.Cipher.encrypt_chacha20/2 instead.
@spec encrypt_chacha20(binary(), binary()) :: binary()

Encrypts plaintext with ChaCha20-Poly1305.

generate_ecdh_keypair()

This function is deprecated. Use Apero.Crypto.Key.generate_ecdh_keypair/0 instead.
@spec generate_ecdh_keypair() :: {binary(), binary()}

Generates an X25519 key pair. Returns {private_key, public_key} (both raw binary).

generate_key()

This function is deprecated. Use Apero.Crypto.Random.generate_key/0 instead.
@spec generate_key() :: binary()

Generates a random 256-bit key.

generate_rsa_keypair()

This function is deprecated. Use Apero.Crypto.Key.generate_rsa_keypair/0 instead.
@spec generate_rsa_keypair() :: {:ok, {binary(), binary()}} | {:error, term()}

Generates an RSA key pair (2048-bit). Returns {private_der, public_der}.

hmac(secret, data)

This function is deprecated. Use Apero.Crypto.Hash.hmac/2 instead.
@spec hmac(binary(), binary()) :: binary()

HMAC-SHA256 (hex encoded).

md5(data)

This function is deprecated. Use Apero.Crypto.Hash.md5/1 instead.
@spec md5(binary()) :: binary()

MD5 hash (hex encoded). NOTE: MD5 is cryptographically broken — only for checksums.

pbkdf2(password, salt, opts \\ [])

This function is deprecated. Use Apero.Crypto.Key.pbkdf2/3 instead.
@spec pbkdf2(binary(), binary(), keyword()) :: binary()

Derives a key using PBKDF2-HMAC-SHA256.

random_hex(bytes \\ 32)

This function is deprecated. Use Apero.Crypto.Random.random_hex/1 instead.
@spec random_hex(non_neg_integer()) :: binary()

Generates a random hex string.

random_password(length \\ 24, opts \\ [])

This function is deprecated. Use Apero.Crypto.Random.random_password/2 instead.
@spec random_password(
  non_neg_integer(),
  keyword()
) :: binary()

Generates a random password with configurable length and character sets.

random_token(bytes \\ 32)

This function is deprecated. Use Apero.Crypto.Random.random_token/1 instead.
@spec random_token(non_neg_integer()) :: binary()

Generates a random URL-safe token.

secure_compare(a, b)

This function is deprecated. Use Apero.Crypto.Random.secure_compare/2 instead.
@spec secure_compare(binary(), binary()) :: boolean()

Timing-safe string comparison.

sha256(data)

This function is deprecated. Use Apero.Crypto.Hash.sha256/1 instead.
@spec sha256(binary()) :: binary()

SHA-256 hash (hex encoded).

sha512(data)

This function is deprecated. Use Apero.Crypto.Hash.sha512/1 instead.
@spec sha512(binary()) :: binary()

SHA-512 hash (hex encoded).

stream_encrypt(arg, chunk)

This function is deprecated. Use Apero.Crypto.Cipher.stream_encrypt/2 instead.
@spec stream_encrypt(
  {any(), binary()},
  binary()
) :: {any(), binary(), binary()}

Encrypts a chunk of data in streaming mode.

stream_finalize(state)

This function is deprecated. Use Apero.Crypto.Cipher.stream_finalize/1 instead.
@spec stream_finalize(any()) :: binary()

Finalizes a streaming encryption. Returns the final state (discard after).

stream_init(key)

This function is deprecated. Use Apero.Crypto.Cipher.stream_init/1 instead.
@spec stream_init(binary()) :: {any(), binary()}

Starts an AES-256-CTR encryption stream. Use with stream_encrypt/2 and stream_finalize/1.