Excited to tell you that our welfare activity has been upgraded - Paying only $5.00 + Freight to get JCOP J3H145 card and A40CR card.
Please check this post for more details.

Moreover, if you want to get Free Samples by Paying Freight only , please check this page.

Combine two byte array and encrypt them togethor

Applets Development Guide

Moderator: product

OSSAMA
Posts: 6
Joined: Sun Mar 19, 2017 8:54 am
Points :190
Contact:

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.
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);		
	}

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer