Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Security / August 2006

Tip: Looking for answers? Try searching our database.

Secret Key generation

Thread view: 
igor.medeiros@gmail.com - 03 Aug 2006 14:12 GMT
Hello everybody,

I need to crypt a seed with a 3DES key, but the problem is that this
symmetric key was generated by a smart card and have ony 16 bytes, and
when I try to generate with the following code

----------------------------------
// sample of session key
byte[] keyBytes = {(byte)0x00, (byte)0xE5, (byte)0x14, (byte)0x5F,
(byte)0xA7, (byte)0x45, (byte)0x36, (byte)0x76, (byte)0x31, (byte)0x7D,
(byte)0x4C, (byte)0x38, (byte)0x1C, (byte)0x64, (byte)0xE2,
(byte)0xD2};

KeySpec keyspec = new DESedeKeySpec(keyBytes);

SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede");

SecretKey key = keyfactory.generateSecret(keyspec);
--------------------------------------------------

I get the exception: java.security.InvalidKeyException: Wrong key size
but if the key have 24 bytes it works. So, is possible to make
something like a padding on the key?

Thanks in advance,
Igor Medeiros
Mr. Skeptic - 08 Aug 2006 02:57 GMT
> Hello everybody,
>
[quoted text clipped - 22 lines]
> Thanks in advance,
> Igor Medeiros

The smart card probably implements Triple-DES in EDE mode, whereas the
JCE does full 3 key triple-DES. The solution is (hopefully) to append a
copy of the first 8 bytes to the end of keyBytes, i.e.

byte[] keyBytes = {(byte)0x00, (byte)0xE5, (byte)0x14, (byte)0x5F,
(byte)0xA7, (byte)0x45, (byte)0x36, (byte)0x76, (byte)0x31,
(byte)0x7D,
(byte)0x4C, (byte)0x38, (byte)0x1C, (byte)0x64, (byte)0xE2,
(byte)0xD2,
(byte)0x00, (byte)0xE5, (byte)0x14, (byte)0x5F,
(byte)0xA7, (byte)0x45, (byte)0x36, (byte)0x76};


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.