TLVList Error

310 views
Skip to first unread message

Annisah S

unread,
Sep 26, 2016, 10:02:09 AM9/26/16
to jPOS Users
Hello,

I want to extract a TLV message, but why there is an error at tag 6F02?
bellow is the code : 


  byte[] tlv = ISOUtil.hex2byte("5F02024669") ;
  TLVList t = new TLVList();
  t.unpack(tlv);  
  t.dump(System.out, " ");
  
  results : 
  <tlvlist>
    <tag id='5f02' value='4669' />
 </tlvlist>


When im trying to change like this, it was throwing an exception

  byte[] tlv = ISOUtil.hex2byte("6F02024669") ;
  TLVList t = new TLVList();
  t.unpack(tlv);  
  t.dump(System.out, " ");



Exception in thread "main" org.jpos.iso.ISOException: BAD TLV FORMAT - tag (69) without length or value




BR


Nisa


chhil

unread,
Sep 26, 2016, 10:06:58 AM9/26/16
to jpos-...@googlegroups.com

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/2989571e-1f4b-4783-87fb-89afd7425376%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

chhil

unread,
Sep 26, 2016, 10:26:23 AM9/26/16
to jpos-...@googlegroups.com
If you are parsing emv and not generic tlv data, emv can have tags that are 2 wide or 4 wide and there is info in the tag which tells it if it need to parse more bytes for the tag. 
When it parses 5F it determines that it needs to get the next 2 bytes to form the tag, where as when its 6F it does not and causes parsing to fail, as its not valid data. You should read up on ber tlv encoding, which the tlvlist implements.

-chhil

Andy Orrock

unread,
Sep 26, 2016, 10:36:36 AM9/26/16
to jpos-...@googlegroups.com
Right.

You need to do some serious study on BER-TLV.  EMV uses it for example.  I wrote this in an internal document:

EMV tags use the ‘BER-TLV’ scheme of encoding – the length of the tag is determined by the value of last five bits of the first byte. If they’re all 1s, then the tag has a second byte. For example, these tags are expressed in two bytes:

• 5F34 – 0101 1111 0011 0100
• 9F37 – 1001 1111 0011 0111

These tags are expressed in one byte:

• 4F – 0100 1111
• 50 – 0101 0000
• 9B – 1001 1011

--------
Andy

Reply all
Reply to author
Forward
0 new messages