First of all, do not use DES. It has been destroyed since many years. Use AES instead.
The problem I am facing is that I get my key for encryption and obviously I need the same key for decryption.
If you use symmetric cryptography techniques, this is it. Otherwise, pay attention to asymmetric encryption .
But this seems like a paradox, because if I save my key in a file or in a database, someone cannot get the key and decrypt my file?
Yes, someone could do it.
Maybe I am missing something, but is there a way to generate a key using a supplied pass phrase?
The key is not used using the passphrase. Usually you do the following:
- key generation
- encrypt a key generated using a symmetric key obtained from a passphrase
And why does someone not want to use the passkey if they have to store the generated key in another place?
There may be several reasons. For example, you can save the key on a removable device, and you just want to connect it to the computer to extract the key without entering a passphrase. The lack of a passphrase also has a drawback: the passphrase must be remembered, you can guess if it takes too long, maybe you will write it down (and this is the same, and then save it in a file)
EDIT:
to generate a password key, see PBKDF2 ( linked post ).
source share