# Key derivation function

Derive a key of any length from a passphrase or seed with PBKDF2, scrypt, Argon2id, or HKDF — hex or base64, in your browser. Nothing is uploaded.

## Run it

- **CLI:** `gizza tool key-derive 'algorithm=pbkdf2'`
- **Web:** https://gizza.ai/tools/key-derive/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/key-derive/tool.json

## Inputs

- `algorithm` — Algorithm _(field)_
- `secret` — Passphrase / seed _(field)_
- `input_encoding` — Secret encoding _(field)_
- `salt` — Salt _(field)_
- `salt_encoding` — Salt encoding _(field)_
- `length` — Output length (bytes) _(field)_
- `encoding` — Output encoding _(field)_
- `hash` — Hash (PBKDF2 / HKDF) _(field)_
- `iterations` — Iterations (PBKDF2) _(field)_
- `n` — N — cost (scrypt) _(field)_
- `r` — r — block size (scrypt) _(field)_
- `p` — p — parallelization (scrypt) _(field)_
- `memory_kib` — Memory KiB (Argon2) _(field)_
- `time_cost` — Time cost (Argon2) _(field)_
- `parallelism` — Parallelism (Argon2) _(field)_
- `argon2_variant` — Argon2 variant _(field)_
- `info` — Info / context (HKDF) _(field)_
- `info_encoding` — Info encoding (HKDF) _(field)_

## Output

- Derived key (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `algorithm` — Algorithm
- `secret` — Passphrase / seed
- `input_encoding` — Secret encoding
- `salt` — Salt
- `salt_encoding` — Salt encoding
- `length` — Output length (bytes)
- `encoding` — Output encoding
- `hash` — Hash (PBKDF2 / HKDF)
- `iterations` — Iterations (PBKDF2)
- `n` — N — cost (scrypt)
- `r` — r — block size (scrypt)
- `p` — p — parallelization (scrypt)
- `memory_kib` — Memory KiB (Argon2)
- `time_cost` — Time cost (Argon2)
- `parallelism` — Parallelism (Argon2)
- `argon2_variant` — Argon2 variant
- `info` — Info / context (HKDF)
- `info_encoding` — Info encoding (HKDF)

Example: `https://gizza.ai/tools/key-derive/?algorithm=pbkdf2&secret=The%20passphrase%20or%20key%20material%20to%20derive%20from&input_encoding=utf8&salt=Salt%20%28required%20for%20Argon2%2C%20min%208%20bytes%29&salt_encoding=utf8&length=32&encoding=hex&hash=sha256&iterations=100000&n=16384&r=8&p=1&memory_kib=19456&time_cost=2&parallelism=1&argon2_variant=argon2id&info=application%20context%20string&info_encoding=utf8`

---

## About this tool

A **key derivation function (KDF)** turns a passphrase or a piece of key material
into a cryptographic key of a chosen length. This tool is one unified selector for
the four KDFs you actually reach for:

- **PBKDF2** (RFC 2898) — the widely-supported password-based KDF; pick a hash
  (SHA-1/256/384/512) and an iteration count.
- **scrypt** (RFC 7914) — memory-hard, tuned with the classic `N` / `r` / `p`
  parameters.
- **Argon2** — the modern memory-hard winner of the Password Hashing Competition.
  Here it returns **raw key material of your chosen length** (via
  `hash_password_into`), not a PHC storage hash — pick `argon2id` (default),
  `argon2i`, or `argon2d` and set memory, time cost, and parallelism.
- **HKDF** (RFC 5869) — an extract-and-expand KDF for turning existing
  **high-entropy** key material (a shared secret, a random seed) into one or more
  keys, with an optional `info` context string. HKDF is *not* meant for deriving
  keys from a low-entropy password — use PBKDF2, scrypt, or Argon2 for that.

Enter your secret and salt as UTF‑8 text, hex, or base64, choose the output length
in bytes, and read the derived key back as hex or base64. The computation runs
entirely in your browser via WebAssembly — nothing is uploaded, and the same
inputs always produce the same key, so results are reproducible against other
standards-compliant libraries.

## FAQ

<details>
<summary>Which algorithm should I use?</summary>

For deriving a key from a **password or passphrase**, prefer **Argon2id** (or
scrypt / PBKDF2 where you need broad compatibility) — they are deliberately slow
and memory-hard to resist brute force. For expanding an already **high-entropy**
value such as a Diffie-Hellman shared secret or a random seed into one or more
subkeys, use **HKDF**. PBKDF2 with a high iteration count remains a safe,
universally-available choice when the others aren't an option.

</details>

<details>
<summary>How is this different from a password hasher like Argon2 PHC?</summary>

A password hasher emits a self-describing **PHC string** (for example
`$argon2id$v=19$m=19456,t=2,p=1$…`) meant to be stored and later verified. This
tool instead returns **raw key bytes of the length you ask for** — the material
you feed into AES, HMAC, or another primitive. The Argon2 path uses
`hash_password_into` so you get chosen-length key material rather than a storage
hash.

</details>

<details>
<summary>Why does Argon2 require a salt of at least 8 bytes?</summary>

The Argon2 specification mandates a minimum salt length of 8 bytes, and the
reference implementation rejects anything shorter. Use a unique, random salt of
at least 16 bytes per key in production. PBKDF2 and scrypt also strongly benefit
from a random salt; HKDF's salt is optional (an empty salt is treated as a string
of zeros, per RFC 5869).

</details>

<details>
<summary>Are the results deterministic and standards-compliant?</summary>

Yes. Given the same secret, salt, parameters, and output length, every KDF here
produces the same bytes on every run, matching the published RFC test vectors
(RFC 6070 for PBKDF2, RFC 7914 for scrypt, RFC 5869 for HKDF, and the Argon2
reference vectors). That makes the output reproducible against other compliant
libraries such as OpenSSL, PyCryptodome, or Node's `crypto`.

</details>

## Related tools

- [HKDF key derivation](https://gizza.ai/tools/hkdf-derive/): Derive keys with HKDF, the HMAC-based extract-and-expand KDF from RFC 5869 — choose hash, salt, info label, length and hex/base64 output, all in your browser.
- [PBKDF2 key derivation](https://gizza.ai/tools/pbkdf2-derive/): Derive a key from a password with PBKDF2-HMAC (SHA-1/256/512). Pick iterations, salt, length and hex/base64 output — all in your browser. Nothing is uploaded.
- [scrypt key derivation](https://gizza.ai/tools/scrypt-derive/): Derive a key from a password with the scrypt memory-hard KDF (RFC 7914). Set N, r, p, salt and hex/base64 output — free and fully in-browser.
- [Argon2 hash](https://gizza.ai/tools/argon2-hash/): Hash a password with Argon2id (configurable memory, iterations, parallelism) and get a PHC string, or verify a password — in your browser. Nothing is uploaded.
- [Hash Identifier](https://gizza.ai/tools/hash-identifier/): Paste a hash and instantly identify its likely algorithm — bcrypt, Argon2, MD5, SHA-1/256/512, NTLM, sha512crypt, PHPass and more. Runs entirely in your browser.
