Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Java parser for BER-TLV?

Tags:

java

parsing

tlv

I'm new to Java, so I would like to use the standard solution for, I think, the standard task. The length of tags and values ​​are not known.

like image 780
Zharro Avatar asked Jul 13 '12 15:07

Zharro


1 Answers

You can use this BER-TLV parser: source code on git.
Examples:

How to parse

byte[] bytes = HexUtil.parseHex("50045649534157131000023100000033D44122011003400000481F");
BerTlvParser parser = new BerTlvParser(LOG);
BerTlvs tlvs = parser.parse(bytes, 0, bytes.length);

How to build

byte[] bytes =  new BerTlvBuilder()
                .addHex(new BerTag(0x50), "56495341")
                .addHex(new BerTag(0x57), "1000023100000033D44122011003400000481F")
                .buildArray();

Maven dependency

<dependency>
  <groupId>com.payneteasy</groupId>
  <artifactId>ber-tlv</artifactId>
  <version>1.0-10</version>
</dependency>
like image 82
Maksym Avatar answered Sep 21 '22 17:09

Maksym