C# .NET library for reading and writing TLV (Tag Length Value) encoded data.
This library follows the encoding rules defined in the following standards:
- X.690 ASN.1 encoding rules (ISO/IEC 8825–1):
- Basic Encoding Rules (BER)
- Canonical Encoding Rules (CER)
- Distinguished Encoding Rules (DER)
- EMV 4.2 Book 3, Annex B: Rules for BER-TLV Data Objects
To read all TLV encoded data from a stream/byte array:
TlvEncoding.ProcessTlvStream(stream,
(tag, data) => {
Console.WriteLine($"Tag:{tag} Data:{BitConverter.ToString(data)}");
});
To write a tag-length-value entry to a stream:
WriteTlv(stream, tag, tagData);
Low level read access:
var tag = TlvEncoding.ReadNextTag(stream);
var length = TlvEncoding.ReadLength(stream);
Low level write access:
TlvEncoding.WriteTag(stream, tag);
TlvEncoding.WriteLength(stream, length);
Available from NuGet: https://www.nuget.org/packages/TlvLib