Urgent.News

What's breaking now, across thousands of outlets.

Tech

Why You Can't Just Use a Password as an Encryption Key

I used to think encryption was simple: take a password, use it as the key, done. Then I built a small encryption tool myself, and realized that's not how any of this works. This is the first post in a series where I'm documenting what I'm actually learning while building CryptoGraphy , a small Python project I'm using to study applied cryptography properly instead of just calling library…

Encryption is not as simple as taking a password and using it as the key. The author learned this the hard way when building their own encryption tool. In the first post of a series, they explain the issues with this approach. AES encryption doesn't accept passwords directly; it requires a specific key size, usually 256 bits or 32 bytes.

Passwords, on the other hand, are variable-length, human-chosen, and have low entropy. If you try to pad or truncate a password to fit the key size, you're not creating a strong key, but rather a weak one that's easy for attackers to guess. Passwords and keys serve different purposes: passwords are meant to be memorable for humans, while keys need to be unpredictable for computers.

The author solves this problem by deriving a key from the password using a key derivation function (KDF), specifically Argon2id. Argon2id takes the password and a random salt as inputs and produces a 32-byte key through a computationally expensive process. This makes guessing the password through brute force a slow and expensive attack.

The author emphasizes that the key derivation function's output size is crucial, not just the fact that it produces the correct length. The takeaway is that passwords and keys are fundamentally different, and treating them as interchangeable is a common mistake in homemade crypto solutions. The author encourages readers to ask about the key derivation process and its resistance to attacks when building systems that handle encryption.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Tuesday 1 September →