Here is part of the applet code in my card.
Code: Select all
cipherDES = Cipher.getInstance(Cipher.ALG_DES_CBC_NOPAD, false);
key = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_3KEY, false);
key.setKey(KEY_BYTES, (short) 0);
//Encrypt message
cipherDES.init(key, Cipher.MODE_ENCRYPT);
cipherDES.doFinal(tempMessage, startOffset, inLength, tempMessage, startOffset);
The key is 24 bytes length.After I execute the encryption in my card and I obtain the encrypted text.
Then I try to decrypt the encrypted text in the normal Java application but the decrypted text has nothing to do with the original one. Could some one give me any pointers?
Java applet code to decrypt the text is as below:
Code: Select all
byte[] KEY_BYTES = { (byte) 0x38, (byte) 0x12, (byte) 0xA4,
(byte) 0x19, (byte) 0xC6, (byte) 0x3B, (byte) 0xE7, (byte) 0x71,
(byte) 0x00, (byte) 0x12, (byte) 0x00,(byte) 0x19, (byte) 0x80,
(byte) 0x3B, (byte) 0xE7, (byte) 0x71,
(byte) 0x39, (byte) 0x12, (byte) 0xA4,
(byte) 0x19, (byte) 0xC6, (byte) 0x3C, (byte) 0xE7, (byte) 0x71};
java.security.spec.AlgorithmParameterSpec alSpec =
new javax.crypto.spec.IvParameterSpec(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00});
try {
Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY_BYTES,"DESede"),alSpec);
byte[] decrypted = cipher.doFinal(data);
return new String(decrypted);