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!

3DES Encrypt and decrypt (Urgent)

843811Jan 5 2006 — edited Jan 15 2007
Hello,

I want to generate a 128 bit key for 3DES Encryption,
KeyGenerator kg = KeyGenerator.getInstance("DESede");
kg.init(128, new SecureRandom());
Key key = kg.generateKey();
System.out.println("Key  : " + key );
System.out.println("key.getEncoded()   : " + key.getEncoded() );
I got error
Exception in thread "main" java.security.InvalidParameterException: Wrong keysiz
e: must be equal to 112 or 168

why I cant using 128?

After I modified to 128, I get the key and keyEncoded :

Key : com.sun.crypto.provider.DESedeKey@b069b130
key.getEncoded() : [B@ece65

I know a key lenght of 3DES is 32byte hex char, why I get such short key ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 12 2007
Added on Jan 5 2006
15 comments
2,031 views