System.Formats.Asn1 10.0.0

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
Aspose.PDF
Aspose.PDF for .NET is a PDF document creation and manipulation component that enables your .NET applications to read, write and manipulate existing PDF documents without using Adobe Acrobat. It also allows you to create forms and manage form fields embedded in a PDF document. This component is written in managed C# and it allows developers to add PDF creation and manipulation functionality to their Microsoft .NET applications (WinForms, ASP.NET and .NET Compact Framework). Aspose.PDF for .NET is affordable and offers an incredible wealth of features including PDF compression options; table creation and manipulation; support for graph objects; extensive hyperlink functionality; extended security controls; custom font handling; integration with data sources; add or remove bookmarks; create table of contents; add, update, delete attachments and annotations; import or export PDF form data; add, replace or remove text and images; split, concatenate, extract or insert pages; transform pages to image; print PDF documents and much more.
119
EPPlus
A spreadsheet library for .NET framework and .NET core
90
MailKit
MailKit is an Open Source cross-platform .NET mail-client library that is based on MimeKit and optimized for mobile devices. Features include: * HTTP, Socks4, Socks4a and Socks5 proxy support. * SASL Authentication via ANONYMOUS, CRAM-MD5, DIGEST-MD5, LOGIN, NTLM, OAUTHBEARER, PLAIN, SCRAM-SHA-1, SCRAM-SHA-256, SCRAM-SHA-512 and XOAUTH2. * A fully-cancellable SmtpClient with support for STARTTLS, 8BITMIME, BINARYMIME, ENHANCEDSTATUSCODES, SIZE, DSN, PIPELINING and SMTPUTF8. * A fully-cancellable Pop3Client with support for STLS, UIDL, APOP, PIPELINING, UTF8, and LANG. * A fully-cancellable ImapClient with support for ACL, QUOTA, LITERAL+, IDLE, NAMESPACE, ID, CHILDREN, LOGINDISABLED, STARTTLS, MULTIAPPEND, UNSELECT, UIDPLUS, CONDSTORE, ESEARCH, SASL-IR, COMPRESS, WITHIN, ENABLE, QRESYNC, SORT, THREAD, ANNOTATE, LIST-EXTENDED, ESORT, METADATA / METADATA-SERVER, NOTIFY, FILTERS, LIST-STATUS, SORT=DISPLAY, SPECIAL-USE / CREATE-SPECIAL-USE, SEARCH=FUZZY, MOVE, UTF8=ACCEPT / UTF8=ONLY, LITERAL-, APPENDLIMIT, STATUS=SIZE, OBJECTID, REPLACE, SAVEDATE, XLIST, and X-GM-EXT1. * Client-side sorting and threading of messages (the Ordinal Subject and the Jamie Zawinski threading algorithms are supported). * Asynchronous versions of all methods that hit the network. * S/MIME, OpenPGP, DKIM and ARC support via MimeKit. * Microsoft TNEF support via MimeKit.
122
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
108
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
83
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.
81
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.
82
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.
88
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.
89
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.
627
System.Management.Automation
Runtime for hosting PowerShell
113
System.Security.Cryptography.Cng
Provides cryptographic algorithm implementations and key management with Windows Cryptographic Next Generation API (CNG). Commonly Used Types: System.Security.Cryptography.RSACng System.Security.Cryptography.ECDsaCng System.Security.Cryptography.CngKey
96
System.Security.Cryptography.Cng
Provides cryptographic algorithm implementations and key management with Windows Cryptographic Next Generation API (CNG). Commonly Used Types: System.Security.Cryptography.RSACng System.Security.Cryptography.ECDsaCng System.Security.Cryptography.CngKey
110
System.Security.Cryptography.OpenSsl
Provides cryptographic algorithm implementations and key management for non-Windows systems with OpenSSL. Commonly Used Types: System.Security.Cryptography.RSAOpenSsl
99
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
131
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
170
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
233
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
237
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
764
System.Security.Cryptography.Pkcs
Provides support for PKCS and CMS algorithms. Commonly Used Types: System.Security.Cryptography.Pkcs.EnvelopedCms
818

https://go.microsoft.com/fwlink/?LinkID=799421

.NET Framework 4.6.2

.NET 8.0

  • No dependencies.

.NET 9.0

  • No dependencies.

.NET 10.0

  • No dependencies.

.NET Standard 2.0

Version Downloads Last updated
10.0.0 58 11/14/2025
10.0.0-rc.2.25502.107 35 10/23/2025
10.0.0-rc.1.25451.107 33 09/15/2025
10.0.0-preview.7.25380.108 35 08/14/2025
10.0.0-preview.6.25358.103 49 07/23/2025
10.0.0-preview.5.25277.114 43 06/08/2025
10.0.0-preview.4.25258.110 46 05/15/2025
10.0.0-preview.3.25171.5 54 04/12/2025
10.0.0-preview.2.25163.2 51 03/25/2025
10.0.0-preview.1.25080.5 53 03/05/2025
9.0.11 44 11/13/2025
9.0.10 35 10/16/2025
9.0.9 33 09/12/2025
9.0.8 44 08/13/2025
9.0.7 44 07/10/2025
9.0.6 39 06/12/2025
9.0.5 52 05/16/2025
9.0.4 45 04/12/2025
9.0.3 49 03/30/2025
9.0.2 49 02/13/2025
9.0.1 47 02/01/2025
9.0.0 60 11/24/2024
9.0.0-rc.2.24473.5 55 11/09/2024
9.0.0-rc.1.24431.7 45 11/25/2024
9.0.0-preview.7.24405.7 51 11/27/2024
9.0.0-preview.6.24327.7 53 12/11/2024
9.0.0-preview.5.24306.7 65 11/28/2024
9.0.0-preview.4.24266.19 70 05/28/2024
9.0.0-preview.3.24172.9 59 05/28/2024
9.0.0-preview.2.24128.5 50 05/05/2024
9.0.0-preview.1.24080.9 66 05/28/2024
8.0.2 55 03/05/2025
8.0.1 89 11/27/2024
8.0.0 1,112 12/18/2023
8.0.0-rc.2.23479.6 54 05/30/2024
8.0.0-rc.1.23419.4 56 05/30/2024
8.0.0-preview.7.23375.6 56 05/28/2024
8.0.0-preview.6.23329.7 86 08/08/2023
8.0.0-preview.5.23280.8 77 05/28/2024
8.0.0-preview.4.23259.5 56 05/28/2024
8.0.0-preview.3.23174.8 58 04/26/2023
8.0.0-preview.2.23128.3 54 05/28/2024
8.0.0-preview.1.23110.8 54 04/26/2023
7.0.0 69 03/09/2023
7.0.0-rc.2.22472.3 60 05/30/2024
7.0.0-rc.1.22426.10 68 05/28/2024
7.0.0-preview.7.22375.6 57 05/28/2024
7.0.0-preview.6.22324.4 59 05/28/2024
7.0.0-preview.5.22301.12 56 05/28/2024
7.0.0-preview.3.22175.4 55 06/06/2022
7.0.0-preview.2.22152.2 68 05/28/2024
6.0.2-mauipre.1.22102.15 59 06/06/2022
6.0.2-mauipre.1.22054.8 56 06/06/2022
6.0.1 62 11/27/2024
6.0.0-rc.2.21480.5 54 05/30/2024
6.0.0-rc.1.21451.13 59 05/28/2024
6.0.0-preview.7.21377.19 54 05/28/2024
6.0.0-preview.5.21301.5 56 05/28/2024
6.0.0-preview.4.21253.7 50 06/06/2022
6.0.0-preview.1.21102.12 54 06/06/2022
5.0.0-preview.8.20407.11 59 05/28/2024
5.0.0-preview.7.20364.11 55 05/28/2024