Skip to content

C# .NET library for working with TLV (Tag Length Value) encoded data

License

Notifications You must be signed in to change notification settings

cgreenza/TlvLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TlvLib

C# .NET library for reading and writing TLV (Tag Length Value) encoded data.

Standards

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

Examples in C#

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);

NuGet Package

Available from NuGet: https://www.nuget.org/packages/TlvLib

About

C# .NET library for working with TLV (Tag Length Value) encoded data

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages