AsnEncodedData Class


Represents Abstract Syntax Notation One (ASN.1)-encoded data.

Namespace:   System.Security.Cryptography
Assembly:  System (in System.dll)

Public Class AsnEncodedData


Initializes a new instance of the AsnEncodedData class.


Initializes a new instance of the AsnEncodedData class using an instance of the AsnEncodedData class.


Initializes a new instance of the AsnEncodedData class using a byte array.

System_CAPS_pubmethodAsnEncodedData(Oid, Byte())

Initializes a new instance of the AsnEncodedData class using an Oid object and a byte array.

System_CAPS_pubmethodAsnEncodedData(String, Byte())

Initializes a new instance of the AsnEncodedData class using a byte array.


Gets or sets the Oid value for an AsnEncodedData object.


Gets or sets the Abstract Syntax Notation One (ASN.1)-encoded data represented in a byte array.


Copies information from an AsnEncodedData object.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Returns a formatted version of the Abstract Syntax Notation One (ASN.1)-encoded data as a string.


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

Abstract Syntax Notation One (ASN.1), which is defined in CCITT Recommendation X.208, is a way to specify abstract objects that will be serially transmitted. The set of ASN.1 rules for representing such objects as strings of ones and zeros is called the Distinguished Encoding Rules (DER), and is defined in CCITT Recommendation X.509, Section 8.7. These encoding methods are currently used by the cryptography namespace in the .NET Framework.

Note that if an unknown data type is encountered while accessing an instance of this class, data is returned as a hexadecimal string.

The following code example shows how to use the AsnEncodedData class.

Imports System
Imports System.Security.Cryptography
Imports System.Security.Cryptography.X509Certificates

Class AsnEncodedDataSample
   Shared msg As String
   Shared Sub Main()
      'The following example demonstrates the usage the AsnEncodedData classes.
      ' Asn encoded data is read from the extensions of an X509 certificate.
         ' Open the certificate store.
         Dim store As New X509Store("MY", StoreLocation.CurrentUser)
         store.Open((OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly))
         Dim collection As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection)
         Dim fcollection As X509Certificate2Collection = CType(collection.Find(X509FindType.FindByTimeValid, DateTime.Now, False), X509Certificate2Collection)
         ' Select one or more certificates to display extensions information.
         Dim scollection As X509Certificate2Collection = X509Certificate2UI.SelectFromCollection(fcollection, "Certificate Select", "Select certificates from the following list to get extension information on that certificate", X509SelectionFlag.MultiSelection)

         ' Create a new AsnEncodedDataCollection object.
         Dim asncoll As New AsnEncodedDataCollection()
         Dim i As Integer
         For i = 0 To scollection.Count - 1
            ' Display certificate information.
	    msg = "Certificate name: "& scollection(i).GetName()

            ' Display extensions information.
            Dim extension As X509Extension
            For Each extension In  scollection(i).Extensions
               ' Create an AsnEncodedData object using the extensions information.
               Dim asndata As New AsnEncodedData(extension.Oid, extension.RawData)
	       msg = "Extension type: " & extension.Oid.FriendlyName & Environment.NewLine & "Oid value: " & asndata.Oid.Value _
		& Environment.NewLine & "Raw data length: " & asndata.RawData.Length & Environment.NewLine _
		& asndata.Format(True) & Environment.NewLine

               ' Add the AsnEncodedData object to the AsnEncodedDataCollection object.
            Next extension
         Next i
	 msg = "Number of AsnEncodedData items in the collection: " & asncoll.Count

         'Create an enumerator for moving through the collection.
         Dim asne As AsnEncodedDataEnumerator = asncoll.GetEnumerator()
         'You must execute a MoveNext() to get to the first item in the collection.
         ' Write out AsnEncodedData in the collection.
	 msg = "First AsnEncodedData in the collection: " & asne.Current.Format(True)

	 msg = "Second AsnEncodedData in the collection: " & asne.Current.Format(True)

         'Return index in the collection to the beginning.
         MsgBox("Information could not be written out for this certificate.")
      End Try
   End Sub 'Main
End Class 'AsnEncodedDataSample

.NET Framework
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top