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
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