How to store a key ?

Do you know how to store a generated key for future use ?

What I'm trying to do is:

1. Encrypt the given data in a simple way:

KeyGenerator kg = KeyGenerator.getInstance("DES");

Key key = kg.generateKey();

Cipher cipher = Cipher.getInstance("DES");

.... // encrypting goes here

2. Store the encrypted data to a file.

3. Run the application again, read the file and decrypt the data, so that I can use it in some way.

I've got everything working except the decryption point - I get an exception - which I don't get if I do not restart the app and thus keep the original key used for encryption.

I assume I need to store the original encryption key somehow if I want to decrypt the file.

How can I do this ?

Thanks a lot in advance :)

[818 byte] By [it-developer.orga] at [2007-11-27 11:55:51]
# 1

Or is there any way to generate the same key every time I run the KeyGenerator.generateKey() method ?

it-developer.orga at 2007-7-29 19:04:18 > top of Java-index,Security,Cryptography...
# 2

I came across a solution on google, so in case anyone is interested, follow the link:

http://articles.techrepublic.com.com/5100-3513_11-1045749.html#

it-developer.orga at 2007-7-29 19:04:18 > top of Java-index,Security,Cryptography...