Java AES interface-- Key generataion questions

B

bsdmike

Hello,
I am trying to write a simple program that encrypts and decrypts a
buffer.
I have found a good example, but I have some questions.

Example:

KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128); // 192 and 256 bits may not be available
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");

Question: If I did a skeySpec.getEncoded() could I turn the raw bytes
back
into an skeySpec? How?

I need to generate a key, display it, encrypt text with it, write the
text and key to
a file, retrieve them and decode the text.

Thanks,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top