Skip to content

codemations/Asn1

Repository files navigation

Nuget Build Status Quality Gate Status

Serialization/Deserialization with Codemations.Asn1

Example class 1:

[AsnSequence]
public class FooQuestion
{
    [AsnElement]
    public BigInteger TrackingNumber { get; set; }
    [AsnElement]
    public string Question { get; set; }
}

Serialization:

var myQuestion = new FooQuestion
{
    TrackingNumber = 5,
    Question = "Anybody there?"
};
AsnConvert.Serialize(myQuestion, AsnEncodingRules.DER);

Output (hex):

30, 13,
    02, 01, 05,
    16, 0e, 41, 6e, 79, 62, 6f, 64, 79, 20, 74, 68, 65, 72, 65, 3f

Deserialization:

var encodedData = new byte[] {
    0x30, 0x13, 0x02, 0x01, 0x05, 0x16, 0x0e, 0x41, 0x6e, 0x79, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, 0x3f
};

AsnConvert.Deserialize<FooQuestion>(encodedData, AsnEncodingRules.DER);

Footnotes

  1. https://en.wikipedia.org/wiki/ASN.1

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages