Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

key.getEncoded()

mohanr-JavaNetAug 13 2010 — edited Aug 13 2010
Hi,
My AES key has some characters like '$' etc. So the normal methods to convert string to byte and byte to string didn't seem to work because they use this set of characters.

public static String strHexVal = "0123456789abcdef";
So I have started using CharsetEncoder, ByteBuffer and CharBuffer and now I am able to encode and decode this sample string successfully.

ByteBuffer bbuf = encoder.encode(CharBuffer.wrap( "Te$$$st" ));

		    CharBuffer cbuf = decoder.decode(bbuf);
But when I use this code to read an actual key from a JCEKS keystore
	        Key key = store.getKey( "aesfileencryption", getPassword() );

	        CharBuffer cbuf = decoder.decode( key.getEncoded() );
I don't get the correct key.

What am I missing ?


Thanks,
Mohan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 10 2010
Added on Aug 13 2010
8 comments
708 views