In order to thank you for all members' support of our website, we are holding new events - Getting Free Samples by Paying Freight only.
Want to get free samples? Please check this post for more details.

Combine two byte array and encrypt them togethor

Applets Development Guide

Moderator: product

Posts: 6
Joined: Sun Mar 19, 2017 8:54 am
Points :168

Combine two byte array and encrypt them togethor

Post by OSSAMA » Fri Aug 31, 2018 8:09 am

hello everyone,
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.

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)
	        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);
			cipher.init(key, mode);
		cipher.doFinal(buffer, ISO7816.OFFSET_CDATA, len, buffer, (short) 0);
		apdu.setOutgoingAndSend((short) 0, (short) 32);		

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer