How To Parse and Find TLV Message (EMV Data) Using JPOS 1.x

On my previous article I already show you simple method to parse TLV message using JPOS version 2.x. In this article, I change the JPOS version to 1.x. Since the ISOMsg class does not have getBytes() method to the specific data element, we need new method to get bytes of data element that has TLV data.

//this is method to change String to array of byte
private byte[] stringtoArByte(String value) {
	byte[] hasil = new byte[value.length()];
	for (int i = 0; i < value.length(); i++) {
		hasil[i] = (byte) value.charAt(i);
	}
	return hasil;
}

//method to print all EMV Data
public void printData(ISOMsg isoMsg){
    //EMV data on DE55
    if (iSOMsg.hasField(55)) {
        TLVList tlvData = new TLVList();
        tlvData.unpack(stringtoArByte(isoMsg.getString(55)));
        for (TLVMsg tLVMsg : tlvData.getTags()) {
            System.out.println("EMVtag : " + Integer.toHexString(tLVMsg.getTag()));
            System.out.println("Value on String Type : " + ISOUtil.hexString(tLVMsg.getValue()));
        }
    }
}

If you want to get value from specific tag, this is the sample example.

public boolean hasTag(int tag){
	return tlvData.findIndex(tag) > -1;
}

//value of tag use hexaint 
//example for PAN Sequence Number, you use 0x5F34
public void printSpecificTag(int tag, TLVList tlvData){
	String toPrint = "No Data..!!";
	if(hasTag(tag)){
		toPrint = "Value from tag " + Integer.toHexString(tag) + " : " + tlvData.find(tag).getValue()
	} 
	System.out.println(toPrint);
}

Hope this simpel article can help ­čÖé

Advertisements

How To Parse TLV Message ISO8583 (EMV data) Using JPOS 2.x

Usually if you work with smart card, you will need to find data of some EMV tags. Since EMV has TLV message type, we need to parse the message to get the actual data. Here is one method that you can use.

public void printData(ISOMsg isoMsg){
	//EMV data on DE55
	if (iSOMsg.hasField(55)) {
		TLVList tlvData = new TLVList();
		tlvData.unpack(iSOMsg.getBytes(55));
		for (TLVMsg tLVMsg : tlvData.getTags()) {
			System.out.println("EMVtag : " + Integer.toHexString(tLVMsg.getTag()));
			System.out.println("Value on String Type : " + ISOUtil.hexString(tLVMsg.getValue()));
		}
	}
}