I need to combine two arrays and then encrypt the combined array with my AES.
the first part ( the first array is the Card_Static_Information) and the second part (the second array is the outcoming response data) which will be stored in the buffer.
I have tried many ways but still, no one worked.
your help is very appreciated.
Ossama
Code: Select all
private void GENERATE_APPLICATION_CRYPTOGRAM_AC (APDU apdu, short len)
{
byte[] Card_Static_Information = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16};
if (len <= 0 || len % 16 != 0)
{
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
byte [] buffer = new byte [32];
buffer = apdu.getBuffer();
Util.arrayCopyNonAtomic(Card_Static_Information, (short)0, buffer, (short)16, (short)16);
Key key = getAesKey();
byte mode = buffer[ISO7816.OFFSET_P1] == (byte) 0x00 ? Cipher.MODE_ENCRYPT : Cipher.MODE_DECRYPT;
Cipher cipher = buffer[ISO7816.OFFSET_P2] == (byte) 0x00 ? aesEcbCipher : aesCbcCipher;
if (cipher == aesCbcCipher)
{
cipher.init(key, mode, AESICV, (short) 0, (short) 16);
}
else
{
cipher.init(key, mode);
}
cipher.doFinal(buffer, ISO7816.OFFSET_CDATA, len, buffer, (short) 0);
apdu.setOutgoingAndSend((short) 0, (short) 32);
}