# `Apero.Crypto`
[🔗](https://github.com/Lorenzo-SF/apero/blob/3.0.0/lib/apero/crypto.ex#L1)

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, HMAC
  * `Apero.Crypto.Cipher` — AES-256-GCM, ChaCha20-Poly1305, AES-256-CTR streaming
  * `Apero.Crypto.Key` — PBKDF2, Argon2id, ECDH, RSA key generation
  * `Apero.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).

# `argon2id`

> This function is deprecated. Use Apero.Crypto.Key.argon2id/3 instead.

```elixir
@spec argon2id(binary(), binary(), keyword()) :: {:ok, binary()} | {:error, term()}
```

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

# `compute_ecdh_secret`

> This function is deprecated. Use Apero.Crypto.Key.compute_ecdh_secret/2 instead.

```elixir
@spec compute_ecdh_secret(binary(), binary()) :: {:ok, binary()} | :error
```

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

# `decrypt`

> This function is deprecated. Use Apero.Crypto.Cipher.decrypt/2 instead.

```elixir
@spec decrypt(binary(), binary()) :: {:ok, binary()} | {:error, term()}
```

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

# `decrypt_chacha20`

> This function is deprecated. Use Apero.Crypto.Cipher.decrypt_chacha20/2 instead.

```elixir
@spec decrypt_chacha20(binary(), binary()) :: {:ok, binary()} | :error
```

Decrypts ChaCha20-Poly1305 encrypted data.

# `decrypt_ctr`

> This function is deprecated. Use Apero.Crypto.Cipher.decrypt_ctr/3 instead.

```elixir
@spec decrypt_ctr(binary(), binary(), binary()) :: {:ok, binary()} | :error
```

Decrypts data encrypted with AES-256-CTR streaming.

# `encrypt`

> This function is deprecated. Use Apero.Crypto.Cipher.encrypt/2 instead.

```elixir
@spec encrypt(binary(), binary() | nil) :: {:ok, binary()}
```

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

# `encrypt_chacha20`

> This function is deprecated. Use Apero.Crypto.Cipher.encrypt_chacha20/2 instead.

```elixir
@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.

```elixir
@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.

```elixir
@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.

```elixir
@spec generate_rsa_keypair() :: {:ok, {binary(), binary()}} | {:error, term()}
```

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

# `hmac`

> This function is deprecated. Use Apero.Crypto.Hash.hmac/2 instead.

```elixir
@spec hmac(binary(), binary()) :: binary()
```

HMAC-SHA256 (hex encoded).

# `md5`

> This function is deprecated. Use Apero.Crypto.Hash.md5/1 instead.

```elixir
@spec md5(binary()) :: binary()
```

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

# `pbkdf2`

> This function is deprecated. Use Apero.Crypto.Key.pbkdf2/3 instead.

```elixir
@spec pbkdf2(binary(), binary(), keyword()) :: binary()
```

Derives a key using PBKDF2-HMAC-SHA256.

# `random_hex`

> This function is deprecated. Use Apero.Crypto.Random.random_hex/1 instead.

```elixir
@spec random_hex(non_neg_integer()) :: binary()
```

Generates a random hex string.

# `random_password`

> This function is deprecated. Use Apero.Crypto.Random.random_password/2 instead.

```elixir
@spec random_password(
  non_neg_integer(),
  keyword()
) :: binary()
```

Generates a random password with configurable length and character sets.

# `random_token`

> This function is deprecated. Use Apero.Crypto.Random.random_token/1 instead.

```elixir
@spec random_token(non_neg_integer()) :: binary()
```

Generates a random URL-safe token.

# `secure_compare`

> This function is deprecated. Use Apero.Crypto.Random.secure_compare/2 instead.

```elixir
@spec secure_compare(binary(), binary()) :: boolean()
```

Timing-safe string comparison.

# `sha256`

> This function is deprecated. Use Apero.Crypto.Hash.sha256/1 instead.

```elixir
@spec sha256(binary()) :: binary()
```

SHA-256 hash (hex encoded).

# `sha512`

> This function is deprecated. Use Apero.Crypto.Hash.sha512/1 instead.

```elixir
@spec sha512(binary()) :: binary()
```

SHA-512 hash (hex encoded).

# `stream_encrypt`

> This function is deprecated. Use Apero.Crypto.Cipher.stream_encrypt/2 instead.

```elixir
@spec stream_encrypt(
  {any(), binary()},
  binary()
) :: {any(), binary(), binary()}
```

Encrypts a chunk of data in streaming mode.

# `stream_finalize`

> This function is deprecated. Use Apero.Crypto.Cipher.stream_finalize/1 instead.

```elixir
@spec stream_finalize(any()) :: binary()
```

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

# `stream_init`

> This function is deprecated. Use Apero.Crypto.Cipher.stream_init/1 instead.

```elixir
@spec stream_init(binary()) :: {any(), binary()}
```

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
