Asn1DecoderNet5 1.6.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Asn1DecoderNet5 --version 1.6.0
NuGet\Install-Package Asn1DecoderNet5 -Version 1.6.0
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="Asn1DecoderNet5" Version="1.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Asn1DecoderNet5 --version 1.6.0
#r "nuget: Asn1DecoderNet5, 1.6.0"
#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.
// Install Asn1DecoderNet5 as a Cake Addin
#addin nuget:?package=Asn1DecoderNet5&version=1.6.0

// Install Asn1DecoderNet5 as a Cake Tool
#tool nuget:?package=Asn1DecoderNet5&version=1.6.0

ASN1Decoder

This library aims to facilitate the parsing of ASN.1 data. It provides a data decoder and a set of methods for their parsing.

NuGet package

Decoding

The class Asn1DecoderNet5.Decoder is used for decoding DER data. Specifically, the static method Decode returns an Asn1DecoderNet5.Interfaces.ITag object.

ITag decodedDataStructure = Asn1DecoderNet5.Decoder.Decode(dataByteArray);

Working with the decoded data

Get a string representation

To obtain the string representation of the ASN.1 structure, you can utilize this extension method:

string result = decodedDataStructure.ToPrettyString(" | ", 128);

This method accepts two parameters. The first parameter is a string used to control the indentation of each element. The second parameter is the maximum length of a single line in the resulting string, not including the indentation.

The resulting string will appear as follows:

SEQUENCE
| OBJECT_IDENTIFIER 1.2.840.113549.1.7.2, signedData, PKCS #7
| [0]
|  | SEQUENCE
|  |  | INTEGER 1
|  |  | SET
...

Check if the data is X.509 v3 certificate

To check if the data is actual X.509 certificate use this extension method:

bool isCert = decodedDataStructure.IsCertificate();

Get items SubjectAlternativeName

To get items from the Subject Alternative Name (SAN), you can refer to the unit tests provided in the source code. The unit tests in the linked file will demonstrate how to use the library to extract and work with items from the SAN in ASN.1 data.

TL;DR:

[Fact]
public void Should_GetSan_GetsSanWithMailFromCert()
{
    var tag = Decoder.Decode(Sources.NormalCertificateWithEmailInSan);
    var ok = tag.TryGetSubjectAlternativeName(out var san);
    Assert.True(ok);
    Assert.NotEmpty(san);
    Tags.SAN.Rfc822Name email = null;
    foreach (var item in san)
    {
        if (item.ItemKind == Tags.SAN.SanItemKind.Rfc822Name)
        {
            email = (Tags.SAN.Rfc822Name)item;
            break;
        }
    }
    Assert.NotNull(email);
    Assert.Equal("kral@ica.cz", email.Content);
}
Product 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 was computed.  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. 
.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 net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  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.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.6.1 126 1/22/2024
1.6.0 233 11/8/2023
1.5.3 391 11/28/2022
1.5.2 290 11/28/2022
1.5.1 307 11/20/2022
1.5.0 496 8/21/2022
1.4.0 913 3/7/2022
1.3.0 432 1/21/2022
1.2.0 291 12/9/2021
1.1.0 364 10/28/2021
1.0.8 371 10/5/2021
1.0.7 311 10/4/2021
1.0.6 300 9/20/2021
1.0.5 389 9/12/2021
1.0.4 376 9/12/2021
1.0.2 355 9/11/2021

Added extension methods for easier data parsing. Revisited OID class. Decoding (OID parsing) optimizations.