Is there a Java parser for BER-TLV?

后端 未结 6 1908
暖寄归人
暖寄归人 2020-12-16 04:43

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.

6条回答
  •  温柔的废话
    2020-12-16 05:11

    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

    
      com.payneteasy
      ber-tlv
      1.0-10
    
    

提交回复
热议问题