# Re: problem with writing the generated key to a file

Jan Luehe (luehe@laguna.eng.sun.com)
Tue, 6 Jul 1999 09:55:39 -0700 (PDT)

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Jan Luehe: "Re: JSECURITY Issue: broken link"
- Previous message: Jan Luehe: "Re: Question about examples?"
- Maybe in reply to: Hemant Dhavala: "problem with writing the generated key to a file"

    Message-Id: <199907061655.JAA29814@laguna.eng.sun.com>

    Date: Tue, 6 Jul 1999 09:55:39 -0700 (PDT)

    From: Jan Luehe <luehe@laguna.eng.sun.com>

    Subject: Re: problem with writing the generated key to a file

    To: java-security@java.sun.com, kdhavala@hotmail.com

Hemanth:

> I am developing a client server application where encryption and decryption
> are performed by the server. I was able to generate a symmetric key using
> the generateKey() method of class KeyGenerator.
> But i am not able to write this generated key to a file.
> I would really appreciate if you can help me in this matter.

You should call the getEncoded() method on your Key object,
which returns the byte encoding of your key.
You can then store the returned bytes in a file.
Later, when you need to reinstantiate the Key from its encoding,
you read in the key bytes and pass them to an appropriate
SecretKeyFactory, which will parse them and return a corresponding
Key object.

Note that it is not recommended to store your key bytes in the
clear, because someone else may be able to read them.
You might want to use password-based encryption to protect
your key bytes. JCE 1.2 provides the functionality to do that.

Jan

- Next message: Jan Luehe: "Re: JSECURITY Issue: broken link"
- Previous message: Jan Luehe: "Re: Question about examples?"
- Maybe in reply to: Hemant Dhavala: "problem with writing the generated key to a file"