The length of the input data is random.But When I use javax.crypto to verify, the result is correct.
Here is part of applet code:
Code: Select all
case (byte)0x03:
short updateLen = apdu.setIncomingAndReceive();
if (updateLen != buf[ISO7816.OFFSET_LC]) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
return;
}
try {
short updatedLen = _cipher.update(buf, ISO7816.OFFSET_CDATA, updateLen, buf, (short) 0);
apdu.setOutgoingAndSend((short) 0, updatedLen);
} catch (CryptoException e) {
Util.setShort(buf, (short) 0, e.getReason());
apdu.setOutgoingAndSend((short) 0, (short) 2);
ISOException.throwIt(ISO7816.SW_UNKNOWN);
}
break;
The code that use javax.crypto to verify
Code: Select all
IvParameterSpec ivParameterSpec2 = new IvParameterSpec(iv);
DESKeySpec desKeySpec2 = new DESKeySpec(key);
SecretKeyFactory secretKeyFactory2 = SecretKeyFactory.getInstance("DES");
SecretKey secretKey2 = secretKeyFactory2.generateSecret(desKeySpec2);
Cipher cipher2 = Cipher.getInstance("DES/CBC/NoPadding");
cipher2.init(Cipher.ENCRYPT_MODE, secretKey2, ivParameterSpec2);
byte[] resultData_soft_once = cipher2.update(data);
When using javax.crypto to calculate, the results are always same.