System.Formats.Asn1 11.0.0-rc.2.26504.105

About

Provides functionality for parsing, encoding, and decoding data using Abstract Syntax Notation One (ASN.1). ASN.1 is a standard interface description language for defining data structures that can be serialized and deserialized in a cross-platform way.

Key Features

  • Parse ASN.1 data into .NET types.
  • Encode .NET types into ASN.1 format.
  • Support for BER, CER, DER: Handles Basic Encoding Rules (BER), Canonical Encoding Rules (CER), and Distinguished Encoding Rules (DER).

How to Use

Parsing ASN.1 data:

using System.Formats.Asn1;
using System.Numerics;

// Sample ASN.1 encoded data (DER format)
byte[] asn1Data = [0x30, 0x09, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02, 0x02, 0x01, 0x03];

// Create an AsnReader to parse the data
AsnReader reader = new(asn1Data, AsnEncodingRules.DER);

// Parse the sequence
AsnReader sequenceReader = reader.ReadSequence();

// Read integers from the sequence
BigInteger firstInt = sequenceReader.ReadInteger();
BigInteger secondInt = sequenceReader.ReadInteger();
BigInteger thirdInt = sequenceReader.ReadInteger();

Console.WriteLine($"First integer: {firstInt}");
Console.WriteLine($"Second integer: {secondInt}");
Console.WriteLine($"Third integer: {thirdInt}");

// First integer: 1
// Second integer: 2
// Third integer: 3

Decoding ASN.1 data using AsnDecoder:

using System.Formats.Asn1;
using System.Numerics;
using System.Text;

// Sample ASN.1 encoded data
byte[] booleanData = [0x01, 0x01, 0xFF]; // BOOLEAN TRUE
byte[] integerData = [0x02, 0x01, 0x05]; // INTEGER 5
byte[] octetStringData = [0x04, 0x03, 0x41, 0x42, 0x43]; // OCTET STRING "ABC"
byte[] objectIdentifierData = [0x06, 0x03, 0x2A, 0x03, 0x04]; // OBJECT IDENTIFIER 1.2.3.4
byte[] utf8StringData = [0x0C, 0x05, 0x48, 0x65, 0x6C, 0x6C, 0x6F]; // UTF8String "Hello"

int bytesConsumed;

bool booleanValue = AsnDecoder.ReadBoolean(booleanData, AsnEncodingRules.DER, out bytesConsumed);
Console.WriteLine($"Decoded BOOLEAN value: {booleanValue}, Bytes consumed: {bytesConsumed}");
// Decoded BOOLEAN value: True, Bytes consumed: 3

BigInteger integerValue = AsnDecoder.ReadInteger(integerData, AsnEncodingRules.DER, out bytesConsumed);
Console.WriteLine($"Decoded INTEGER value: {integerValue}, Bytes consumed: {bytesConsumed}");
// Decoded INTEGER value: 5, Bytes consumed: 3

byte[] octetStringValue = AsnDecoder.ReadOctetString(octetStringData, AsnEncodingRules.DER, out bytesConsumed);
Console.WriteLine($"Decoded OCTET STRING value: {Encoding.ASCII.GetString(octetStringValue)}, Bytes consumed: {bytesConsumed}");
// Decoded OCTET STRING value: ABC, Bytes consumed: 5

string objectIdentifierValue = AsnDecoder.ReadObjectIdentifier(objectIdentifierData, AsnEncodingRules.DER, out bytesConsumed);
Console.WriteLine($"Decoded OBJECT IDENTIFIER value: {objectIdentifierValue}, Bytes consumed: {bytesConsumed}");
// Decoded OBJECT IDENTIFIER value: 1.2.3.4, Bytes consumed: 5

string utf8StringValue = AsnDecoder.ReadCharacterString(utf8StringData, AsnEncodingRules.DER, UniversalTagNumber.UTF8String, out bytesConsumed);
Console.WriteLine($"Decoded UTF8String value: {utf8StringValue}, Bytes consumed: {bytesConsumed}");
// Decoded UTF8String value: Hello, Bytes consumed: 7

Encoding ASN.1 data:

// Create an AsnWriter to encode data
AsnWriter writer = new(AsnEncodingRules.DER);

// Create a scope for the sequence
using (AsnWriter.Scope scope = writer.PushSequence())
{
    // Write integers to the sequence
    writer.WriteInteger(1);
    writer.WriteInteger(2);
    writer.WriteInteger(3);
}

// Get the encoded data
byte[] encodedData = writer.Encode();

Console.WriteLine($"Encoded ASN.1 Data: {BitConverter.ToString(encodedData)}");

// Encoded ASN.1 Data: 30-09-02-01-01-02-01-02-02-01-03

Main Types

The main types provided by this library are:

  • System.Formats.Asn1.AsnReader
  • System.Formats.Asn1.AsnWriter
  • System.Formats.Asn1.AsnDecoder
  • System.Formats.Asn1.AsnEncodingRules

Additional Documentation

Feedback & Contributing

System.Formats.Asn1 is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Showing the top 20 packages that depend on System.Formats.Asn1.

Packages Downloads
SSH.NET
SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
99
Microsoft.Identity.Client
This package contains the binaries of the Microsoft Authentication Library for .NET (MSAL.NET). MSAL.NET makes it easy to obtain tokens from the Microsoft identity platform for developers (formerly Azure AD v2.0) signing-in users with work & school accounts, Microsoft personal accounts, and social identities via Azure AD B2C. These tokens provide access to Microsoft Cloud API and any other API secured by the Microsoft identity platform. This version supports adding authentication functionality to your .NET based clients - .NET, .NET Framework, .NET MAUI
77
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
72
Oracle.ManagedDataAccess.Core
Oracle Data Provider for .NET (ODP.NET) Core is a multi-platform ADO.NET driver that provides fast data access from Microsoft .NET (Core) clients to Oracle databases. ODP.NET Core consists of a single 100% managed code dynamic-link library.
72
Oracle.ManagedDataAccess.Core
Oracle Data Provider for .NET (ODP.NET) Core is a multi-platform ADO.NET driver that provides fast data access from Microsoft .NET (Core) clients to Oracle databases. ODP.NET Core consists of a single 100% managed code dynamic-link library.
69
Oracle.ManagedDataAccess.Core
Oracle Data Provider for .NET (ODP.NET) Core is a multi-platform ADO.NET driver that provides fast data access from Microsoft .NET (Core) clients to Oracle databases. ODP.NET Core consists of a single 100% managed code dynamic-link library.
68
Oracle.ManagedDataAccess.Core
Oracle Data Provider for .NET (ODP.NET) Core is a multi-platform ADO.NET driver that provides fast data access from Microsoft .NET (Core) clients to Oracle databases. ODP.NET Core consists of a single 100% managed code dynamic-link library.
67
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild.
67
Oracle.ManagedDataAccess.Core
Oracle Data Provider for .NET (ODP.NET) Core is an ADO.NET driver that provides fast data access from Microsoft .NET Core clients to Oracle databases. ODP.NET Core consists of a single 100% managed code dynamic-link library.
66
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
66
Oracle.ManagedDataAccess.Core
Oracle Data Provider for .NET (ODP.NET) Core is a multi-platform ADO.NET driver that provides fast data access from Microsoft .NET (Core) clients to Oracle databases. ODP.NET Core consists of a single 100% managed code dynamic-link library.
65
EPPlus
A spreadsheet library for .NET framework and .NET core
65
Oracle.ManagedDataAccess.Core
Oracle Data Provider for .NET (ODP.NET) Core is a multi-platform ADO.NET driver that provides fast data access from Microsoft .NET (Core) clients to Oracle databases. ODP.NET Core consists of a single 100% managed code dynamic-link library.
64
Microsoft.Identity.Client
This package contains the binaries of the Microsoft Authentication Library for .NET (MSAL.NET). MSAL.NET makes it easy to obtain tokens from the Microsoft identity platform for developers (formerly Azure AD v2.0) signing-in users with work & school accounts, Microsoft personal accounts, and social identities via Azure AD B2C. These tokens provide access to Microsoft Cloud API and any other API secured by the Microsoft identity platform. This version supports adding authentication functionality to your .NET based clients - .NET, .NET Framework, .NET MAUI
63
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
62
Oracle.ManagedDataAccess.Core
Oracle Data Provider for .NET (ODP.NET) Core is a multi-platform ADO.NET driver that provides fast data access from Microsoft .NET (Core) clients to Oracle databases. ODP.NET Core consists of a single 100% managed code dynamic-link library.
62
Microsoft.Bcl.Cryptography
Provides support for some cryptographic primitives for .NET Framework and .NET Standard.
61
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
60
Oracle.ManagedDataAccess.Core
Oracle Data Provider for .NET (ODP.NET) Core is a multi-platform ADO.NET driver that provides fast data access from Microsoft .NET (Core) clients to Oracle databases. ODP.NET Core consists of a single 100% managed code dynamic-link library.
60

.NET 10.0

  • No dependencies.

.NET 11.0

  • No dependencies.

.NET Framework 4.6.2

.NET Standard 2.0

Version Downloads Last updated
11.0.0-rc.2.26504.105 8 10/13/2026
11.0.0-rc.1.26425.128 20 09/11/2026
11.0.0-preview.7.26381.103 26 08/12/2026
11.0.0-preview.6.26359.118 32 07/15/2026
11.0.0-preview.5.26302.115 31 06/13/2026
11.0.0-preview.4.26230.115 39 05/13/2026
11.0.0-preview.3.26207.106 47 04/16/2026
11.0.0-preview.2.26159.112 45 03/11/2026
11.0.0-preview.1.26104.118 49 02/12/2026
10.0.13 7 10/13/2026
10.0.12 20 09/11/2026
10.0.11 24 08/13/2026
10.0.10 28 07/15/2026
10.0.9 29 06/13/2026
10.0.8 31 05/13/2026
10.0.7 46 04/24/2026
10.0.6 47 04/16/2026
10.0.5 48 03/13/2026
10.0.4 47 03/11/2026
10.0.3 52 02/12/2026
10.0.2 48 01/16/2026
10.0.1 60 12/11/2025
10.0.0 54 12/12/2025
10.0.0-rc.2.25502.107 53 12/12/2025
10.0.0-rc.1.25451.107 50 12/12/2025
10.0.0-preview.7.25380.108 45 12/20/2025
10.0.0-preview.6.25358.103 47 12/12/2025
10.0.0-preview.5.25277.114 47 12/12/2025
10.0.0-preview.4.25258.110 45 12/12/2025
10.0.0-preview.3.25171.5 48 12/12/2025
10.0.0-preview.2.25163.2 41 12/12/2025
10.0.0-preview.1.25080.5 45 12/12/2025
9.0.21 3 10/13/2026
9.0.20 21 09/14/2026
9.0.19 24 08/13/2026
9.0.18 26 07/15/2026
9.0.17 31 06/13/2026
9.0.16 30 05/13/2026
9.0.15 40 04/16/2026
9.0.14 50 03/11/2026
9.0.13 58 02/12/2026
9.0.12 59 01/16/2026
9.0.11 49 12/12/2025
9.0.10 60 12/12/2025
9.0.9 54 12/12/2025
9.0.8 52 01/03/2026
9.0.7 39 01/03/2026
9.0.6 52 12/12/2025
9.0.5 48 12/12/2025
9.0.4 44 12/25/2025
9.0.3 44 12/13/2025
9.0.2 50 12/12/2025
9.0.1 6 10/01/2026
9.0.0 43 12/12/2025
9.0.0-rc.2.24473.5 39 12/12/2025
9.0.0-rc.1.24431.7 5 09/30/2026
9.0.0-preview.7.24405.7 45 12/12/2025
9.0.0-preview.6.24327.7 41 12/12/2025
9.0.0-preview.5.24306.7 46 12/12/2025
9.0.0-preview.4.24266.19 38 12/12/2025
9.0.0-preview.3.24172.9 45 12/12/2025
9.0.0-preview.2.24128.5 47 12/12/2025
9.0.0-preview.1.24080.9 43 12/12/2025
8.0.2 47 12/12/2025
8.0.1 55 12/12/2025
8.0.0 46 12/12/2025
8.0.0-rc.2.23479.6 35 12/12/2025
8.0.0-rc.1.23419.4 40 12/12/2025
8.0.0-preview.7.23375.6 38 12/12/2025
8.0.0-preview.6.23329.7 45 12/12/2025
8.0.0-preview.5.23280.8 43 12/12/2025
8.0.0-preview.4.23259.5 28 12/12/2025
8.0.0-preview.3.23174.8 46 12/11/2025
8.0.0-preview.2.23128.3 45 12/12/2025
8.0.0-preview.1.23110.8 42 12/12/2025
7.0.0 7 10/01/2026
7.0.0-rc.2.22472.3 47 12/12/2025
7.0.0-rc.1.22426.10 36 12/12/2025
7.0.0-preview.7.22375.6 43 12/12/2025
7.0.0-preview.6.22324.4 35 12/12/2025
7.0.0-preview.5.22301.12 47 12/11/2025
7.0.0-preview.4.22229.4 29 12/12/2025
7.0.0-preview.3.22175.4 44 12/12/2025
7.0.0-preview.2.22152.2 39 12/12/2025
7.0.0-preview.1.22076.8 47 12/12/2025
6.0.2-mauipre.1.22102.15 38 12/19/2025
6.0.2-mauipre.1.22054.8 32 12/14/2025
6.0.1 47 12/12/2025
6.0.0 52 12/12/2025
6.0.0-rc.2.21480.5 40 12/12/2025
6.0.0-rc.1.21451.13 43 12/12/2025
6.0.0-preview.7.21377.19 38 12/12/2025
6.0.0-preview.6.21352.12 38 12/12/2025
6.0.0-preview.5.21301.5 42 12/12/2025
6.0.0-preview.4.21253.7 43 12/11/2025
6.0.0-preview.3.21201.4 34 12/12/2025
6.0.0-preview.2.21154.6 39 12/12/2025
6.0.0-preview.1.21102.12 38 12/12/2025
5.0.0 42 12/12/2025
5.0.0-rc.2.20475.5 5 10/01/2026
5.0.0-rc.1.20451.14 39 12/12/2025
5.0.0-preview.8.20407.11 37 12/12/2025
5.0.0-preview.7.20364.11 44 12/12/2025