Using cryptographic hash to match AES key size

I am making a tool for myself where I intend to store cipher text. I wish to use AES together with arbitrary sized keys to create these cipher text strings. The idea is to use a cryptographic hash like SHA256 to compensate for the key length issue.

Is this a sound way of doing things?

Also, since the output domain of SHA256 is much larger than any key a "normal" person can remember, does this add security if an attacker gets hold of the password digest from for example a computer?

-
Why not just use GPG? GPG is infinitely less likely to get the details wrong than you are by building something yourself. – Stephen Touset Jan 30 '14 at 21:06
That is what I am doing right now, but I would like something that fits my needs in terms of updating, deleting and encrypting entities. Also it's a personal project to learn etc. – Mogget Jan 31 '14 at 7:29

1 Answer

Is this a sound way of doing things?

Depends. Where do the keys come from? If they come from a user's memory (e.g., a password) then no. The reason for this is that a simple hash if fairly fast to compute. Typically we recommend people use something like PBKDF2 or scrypt as they run through thousands of iterations. The effect of this is that computing this function once is still fairly fast and user won't notice the delay. Trying to brute force it, however, involves computing the function many, many times. This slows down a brute force attacker significantly. Also, scrypt in particular was designed to be slow on hardware. That means attackers can't throw a GPU or other hardware device at the problem to speed it up.

Also since the output domain of sha256 is much larger than any key a "normal" person can remember, does this add security if an attacker gets hold of the password digest from for example a computer?

No. We often measure security in bits. In particular, bits of entropy. A deterministic function (like sha256) cannot create entropy.

-
Specifically, entropy is a measure of the unknowable parts of a process used to generate a secret. It is not a direct property of the secret itself, and can never be increased through a deterministic process (such as a hash). – Stephen Touset Jan 30 '14 at 21:10