Here is my code.
Code: Select all
byte[] key1 = {(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11};
byte[] cipherText = {(byte)0x9e,(byte)0x90,(byte)0xde,(byte)0x82,(byte)0x74,(byte)0x5e,(byte)0x78,(byte)0x52};
byte[] plainText = new byte[(short)8];
DESKey deskey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES,KeyBuilder.LENGTH_DES, false);
desKey.setKey(key1,(short)0);
Cipher cipherDES = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M2 , false);
cipherDES.init(deskey ,Cipher.MODE_DECRYPT);
try
{
cipherDES.doFinal(cipherText, (short)0, (short)cipherText.length, plainText, (short)0 );
}
catch(CryptoException c)
{
if(c.getReason()==CryptoException.UNINITIALIZED_KEY)
ISOException.throwIt(CryptoException.UNINITIALIZED_KEY);
else if (c.getReason()==CryptoException.ILLEGAL_USE)
ISOException.throwIt(CryptoException.ILLEGAL_USE);
else if(c.getReason()==CryptoException.INVALID_INIT)
ISOException.throwIt(CryptoException.INVALID_INIT);
}