Search code examples
csecurityencryptioncryptographyecryptfs

How to do an aes encryption WITH a user password?


When softwares such as ecryptfs use AES, it asks for a user password (such as "password123").

The AES algorithm by itself does not call for a user password. So where does the "password123" get thrown into the math?

I'm working to make a C function that encrypts some data using a password. I know the typical way of doing it with OpenSSL and an aes key, but I don't know how to get a user password integrated.


Solution

  • You need to use a key derivation function (KDF). Password-Based Key Derivation Function 2 (PBKDF2) is the current most common approach.

    OpenSSL probably exposes PBKDF2, it typically takes in a password and an iteration count (modern systems should use something like 100000 or higher... crank up the number until it takes about 0.3 seconds), and an output length. It may also take a hash function, something in the SHA-2 family (SHA256, SHA384, SHA512) would be a good modern choice.