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