System.Formats.Asn1
9.0.7
Prefix Reserved
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.6.2
This package targets .NET Framework 4.6.2. The package is compatible with this framework or higher.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package System.Formats.Asn1 --version 9.0.7
NuGet\Install-Package System.Formats.Asn1 -Version 9.0.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="System.Formats.Asn1" Version="9.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="System.Formats.Asn1" Version="9.0.7" />
<PackageReference Include="System.Formats.Asn1" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add System.Formats.Asn1 --version 9.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: System.Formats.Asn1, 9.0.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package System.Formats.Asn1@9.0.7
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=System.Formats.Asn1&version=9.0.7
#tool nuget:?package=System.Formats.Asn1&version=9.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
- API documentation
- X.680 - Abstract Syntax Notation One (ASN.1): Specification of basic notation
- X.690 - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER)
Feedback & Contributing
System.Formats.Asn1 is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6.2
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
GitHub repositories (94)
Showing the top 20 popular GitHub repositories that depend on System.Formats.Asn1:
Repository | Stars |
---|---|
MonoGame/MonoGame
One framework for creating powerful cross-platform games.
|
|
mRemoteNG/mRemoteNG
mRemoteNG is the next generation of mRemote, open source, tabbed, multi-protocol, remote connections manager.
|
|
unoplatform/uno
Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
|
|
dotnet/machinelearning
ML.NET is an open source and cross-platform machine learning framework for .NET.
|
|
reactiveui/refit
The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
|
|
serilog/serilog
Simple .NET logging with fully-structured events
|
|
elsa-workflows/elsa-core
A .NET workflows library
|
|
EduardoPires/EquinoxProject
Web Application ASP.NET 9 using Clean Architecture, DDD, CQRS, Event Sourcing and a lot of good practices
|
|
jstedfast/MailKit
A cross-platform .NET library for IMAP, POP3, and SMTP.
|
|
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
|
|
kurrent-io/KurrentDB
KurrentDB is a database that's engineered for modern software applications and event-driven architectures. Its event-native design simplifies data modeling and preserves data integrity while the integrated streaming engine solves distributed messaging challenges and ensures data consistency.
|
|
actions/runner
The Runner for GitHub Actions :rocket:
|
|
DGP-Studio/Snap.Hutao
实用的开源多功能原神工具箱 🧰 / Multifunctional Open-source Genshin Impact Toolkit 🧰
|
|
Azure/azure-powershell
Microsoft Azure PowerShell
|
|
sshnet/SSH.NET
SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
|
|
ravendb/ravendb
ACID Document Database
|
|
fluentassertions/fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, as well as .NET Core 2.1, .NET Core 3.0, .NET 6, .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
|
|
memstechtips/Winhance
Application designed to optimize and customize your Windows experience.
|
|
Sergio0694/ComputeSharp
A .NET library to run C# code in parallel on the GPU through DX12, D2D1, and dynamically generated HLSL compute and pixel shaders, with the goal of making GPU computing easy to use for all .NET developers! 🚀
|
|
CommunityToolkit/Maui
The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
|
Version | Downloads | Last Updated |
---|---|---|
10.0.0-preview.6.25358.103 | 0 | 7/17/2025 |
10.0.0-preview.6.25321.102 | 0 | 6/25/2025 |
10.0.0-preview.5.25280.105 | 0 | 6/2/2025 |
10.0.0-preview.5.25277.114 | 0 | 6/3/2025 |
10.0.0-preview.5.25277.101 | 0 | 5/29/2025 |
10.0.0-preview.4.25255.103 | 0 | 5/12/2025 |
9.0.7 | 1 | 7/11/2025 |