AsnEncodedData Constructors

Definition

Initializes a new instance of the AsnEncodedData class.

Overloads

AsnEncodedData()

Initializes a new instance of the AsnEncodedData class.

AsnEncodedData(Byte[])

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

AsnEncodedData(ReadOnlySpan<Byte>)

Initializes a new instance of the AsnEncodedData class from existing encoded data.

AsnEncodedData(AsnEncodedData)

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

AsnEncodedData(Oid, Byte[])

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

AsnEncodedData(Oid, ReadOnlySpan<Byte>)

Initializes a new instance of the AsnEncodedData class from an object identifier (OID) and existing encoded data.

AsnEncodedData(String, Byte[])

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

AsnEncodedData(String, ReadOnlySpan<Byte>)

Initializes a new instance of the AsnEncodedData class from an object identifier (OID) and existing encoded data.

AsnEncodedData()

Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs

Initializes a new instance of the AsnEncodedData class.

protected:
 AsnEncodedData();
protected AsnEncodedData ();
Protected Sub New ()

Examples

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

#using <System.dll>
#using <System.Security.dll>

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::X509Certificates;

int main()
{
   
   //The following example demonstrates the usage of the AsnEncodedData classes.
   // Asn encoded data is read from the extensions of an X509 certificate.
   try
   {
      
      // Open the certificate store.
      X509Store^ store = gcnew X509Store( L"MY",StoreLocation::CurrentUser );
      store->Open( static_cast<OpenFlags>(OpenFlags::ReadOnly | OpenFlags::OpenExistingOnly) );
      X509Certificate2Collection^ collection = dynamic_cast<X509Certificate2Collection^>(store->Certificates);
      X509Certificate2Collection^ fcollection = dynamic_cast<X509Certificate2Collection^>(collection->Find( X509FindType::FindByTimeValid, DateTime::Now, false ));
      
      // Select one or more certificates to display extensions information.
      X509Certificate2Collection^ scollection = X509Certificate2UI::SelectFromCollection(fcollection, L"Certificate Select",L"Select certificates from the following list to get extension information on that certificate",X509SelectionFlag::MultiSelection);
      
      // Create a new AsnEncodedDataCollection object.
      AsnEncodedDataCollection^ asncoll = gcnew AsnEncodedDataCollection;
      for ( int i = 0; i < scollection->Count; i++ )
      {
         
         // Display certificate information.
         Console::ForegroundColor = ConsoleColor::Red;
         Console::WriteLine( L"Certificate name: {0}", scollection[i]->GetName() );
         Console::ResetColor();
         
         // Display extensions information.
         System::Collections::IEnumerator^ myEnum = scollection[i]->Extensions->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            X509Extension^ extension = safe_cast<X509Extension ^>(myEnum->Current);
            
            // Create an AsnEncodedData object using the extensions information.
            AsnEncodedData^ asndata = gcnew AsnEncodedData( extension->Oid,extension->RawData );
            Console::ForegroundColor = ConsoleColor::Green;
            Console::WriteLine( L"Extension type: {0}", extension->Oid->FriendlyName );
            Console::WriteLine( L"Oid value: {0}", asndata->Oid->Value );
            Console::WriteLine( L"Raw data length: {0} {1}", asndata->RawData->Length, Environment::NewLine );
            Console::ResetColor();
            Console::WriteLine( asndata->Format(true) );
            Console::WriteLine( Environment::NewLine );
            
            // Add the AsnEncodedData object to the AsnEncodedDataCollection object.
            asncoll->Add( asndata );
         }

         Console::WriteLine( Environment::NewLine );

      }
      Console::ForegroundColor = ConsoleColor::Red;
      Console::WriteLine( L"Number of AsnEncodedData items in the collection: {0} {1}", asncoll->Count, Environment::NewLine );
      Console::ResetColor();
      store->Close();
      
      //Create an enumerator for moving through the collection.
      AsnEncodedDataEnumerator^ asne = asncoll->GetEnumerator();
      
      //You must execute a MoveNext() to get to the first item in the collection.
      asne->MoveNext();
      
      // Write out AsnEncodedData in the collection.
      Console::ForegroundColor = ConsoleColor::Blue;
      Console::WriteLine( L"First AsnEncodedData in the collection: {0}", asne->Current->Format(true) );
      Console::ResetColor();
      asne->MoveNext();
      Console::ForegroundColor = ConsoleColor::DarkBlue;
      Console::WriteLine( L"Second AsnEncodedData in the collection: {0}", asne->Current->Format(true) );
      Console::ResetColor();
      
      //Return index in the collection to the beginning.
      asne->Reset();
   }
   catch ( CryptographicException^ ) 
   {
      Console::WriteLine( L"Information could not be written out for this certificate." );
   }

   return 1;
}
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

class AsnEncodedDataSample
{
    static void Main()
    {		
        //The following example demonstrates the usage the AsnEncodedData classes.
        // Asn encoded data is read from the extensions of an X509 certificate.
        try
        {
            // Open the certificate store.
            X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
            X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
            X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
            // Select one or more certificates to display extensions information.
            X509Certificate2Collection scollection = 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.
            AsnEncodedDataCollection asncoll = new AsnEncodedDataCollection();
            for (int i = 0; i < scollection.Count; i++)
            {
                // Display certificate information.
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Certificate name: {0}", scollection[i].GetName());
                Console.ResetColor();
                // Display extensions information.
                foreach (X509Extension extension in scollection[i].Extensions)
                {
                    // Create an AsnEncodedData object using the extensions information.
                    AsnEncodedData asndata = new AsnEncodedData(extension.Oid, extension.RawData);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Extension type: {0}", extension.Oid.FriendlyName);
                    Console.WriteLine("Oid value: {0}",asndata.Oid.Value);
                    Console.WriteLine("Raw data length: {0} {1}", asndata.RawData.Length, Environment.NewLine);
                    Console.ResetColor();
                    Console.WriteLine(asndata.Format(true));
                    Console.WriteLine(Environment.NewLine);
                    // Add the AsnEncodedData object to the AsnEncodedDataCollection object.
                    asncoll.Add(asndata);
                }
                Console.WriteLine(Environment.NewLine);
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Number of AsnEncodedData items in the collection: {0} {1}", asncoll.Count, Environment.NewLine);
            Console.ResetColor();

            store.Close();
            //Create an enumerator for moving through the collection.
            AsnEncodedDataEnumerator asne = asncoll.GetEnumerator();
            //You must execute a MoveNext() to get to the first item in the collection.
            asne.MoveNext();
            // Write out AsnEncodedData in the collection.
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("First AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();

            asne.MoveNext();
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("Second AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();
            //Return index in the collection to the beginning.
            asne.Reset();
        }
        catch (CryptographicException)
        {
            Console.WriteLine("Information could not be written out for this certificate.");
        }
    }
}
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.
      Try
         ' 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()
            MsgBox(msg)

            ' 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
               MsgBox(msg)
        
               ' Add the AsnEncodedData object to the AsnEncodedDataCollection object.
               asncoll.Add(asndata)
            Next extension
         Next i
     msg = "Number of AsnEncodedData items in the collection: " & asncoll.Count
         MsgBox(msg)         
         store.Close()

         '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.
         asne.MoveNext()
         ' Write out AsnEncodedData in the collection.
     msg = "First AsnEncodedData in the collection: " & asne.Current.Format(True)
     MsgBox(msg)
    
         
         asne.MoveNext()
     msg = "Second AsnEncodedData in the collection: " & asne.Current.Format(True)
     MsgBox(msg)
        
         'Return index in the collection to the beginning.
         asne.Reset()
      Catch 
         MsgBox("Information could not be written out for this certificate.")
      End Try
   End Sub
End Class

Applies to

AsnEncodedData(Byte[])

Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs

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

public:
 AsnEncodedData(cli::array <System::Byte> ^ rawData);
public AsnEncodedData (byte[] rawData);
new System.Security.Cryptography.AsnEncodedData : byte[] -> System.Security.Cryptography.AsnEncodedData
Public Sub New (rawData As Byte())

Parameters

rawData
Byte[]

A byte array that contains Abstract Syntax Notation One (ASN.1)-encoded data.

Applies to

AsnEncodedData(ReadOnlySpan<Byte>)

Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs

Initializes a new instance of the AsnEncodedData class from existing encoded data.

public:
 AsnEncodedData(ReadOnlySpan<System::Byte> rawData);
public AsnEncodedData (ReadOnlySpan<byte> rawData);
new System.Security.Cryptography.AsnEncodedData : ReadOnlySpan<byte> -> System.Security.Cryptography.AsnEncodedData
Public Sub New (rawData As ReadOnlySpan(Of Byte))

Parameters

rawData
ReadOnlySpan<Byte>

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

Applies to

AsnEncodedData(AsnEncodedData)

Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs

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

public:
 AsnEncodedData(System::Security::Cryptography::AsnEncodedData ^ asnEncodedData);
public AsnEncodedData (System.Security.Cryptography.AsnEncodedData asnEncodedData);
new System.Security.Cryptography.AsnEncodedData : System.Security.Cryptography.AsnEncodedData -> System.Security.Cryptography.AsnEncodedData
Public Sub New (asnEncodedData As AsnEncodedData)

Parameters

asnEncodedData
AsnEncodedData

An instance of the AsnEncodedData class.

Exceptions

asnEncodedData is null.

Examples

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

#using <System.dll>
#using <System.Security.dll>

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::X509Certificates;

int main()
{
   
   //The following example demonstrates the usage of the AsnEncodedData classes.
   // Asn encoded data is read from the extensions of an X509 certificate.
   try
   {
      
      // Open the certificate store.
      X509Store^ store = gcnew X509Store( L"MY",StoreLocation::CurrentUser );
      store->Open( static_cast<OpenFlags>(OpenFlags::ReadOnly | OpenFlags::OpenExistingOnly) );
      X509Certificate2Collection^ collection = dynamic_cast<X509Certificate2Collection^>(store->Certificates);
      X509Certificate2Collection^ fcollection = dynamic_cast<X509Certificate2Collection^>(collection->Find( X509FindType::FindByTimeValid, DateTime::Now, false ));
      
      // Select one or more certificates to display extensions information.
      X509Certificate2Collection^ scollection = X509Certificate2UI::SelectFromCollection(fcollection, L"Certificate Select",L"Select certificates from the following list to get extension information on that certificate",X509SelectionFlag::MultiSelection);
      
      // Create a new AsnEncodedDataCollection object.
      AsnEncodedDataCollection^ asncoll = gcnew AsnEncodedDataCollection;
      for ( int i = 0; i < scollection->Count; i++ )
      {
         
         // Display certificate information.
         Console::ForegroundColor = ConsoleColor::Red;
         Console::WriteLine( L"Certificate name: {0}", scollection[i]->GetName() );
         Console::ResetColor();
         
         // Display extensions information.
         System::Collections::IEnumerator^ myEnum = scollection[i]->Extensions->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            X509Extension^ extension = safe_cast<X509Extension ^>(myEnum->Current);
            
            // Create an AsnEncodedData object using the extensions information.
            AsnEncodedData^ asndata = gcnew AsnEncodedData( extension->Oid,extension->RawData );
            Console::ForegroundColor = ConsoleColor::Green;
            Console::WriteLine( L"Extension type: {0}", extension->Oid->FriendlyName );
            Console::WriteLine( L"Oid value: {0}", asndata->Oid->Value );
            Console::WriteLine( L"Raw data length: {0} {1}", asndata->RawData->Length, Environment::NewLine );
            Console::ResetColor();
            Console::WriteLine( asndata->Format(true) );
            Console::WriteLine( Environment::NewLine );
            
            // Add the AsnEncodedData object to the AsnEncodedDataCollection object.
            asncoll->Add( asndata );
         }

         Console::WriteLine( Environment::NewLine );

      }
      Console::ForegroundColor = ConsoleColor::Red;
      Console::WriteLine( L"Number of AsnEncodedData items in the collection: {0} {1}", asncoll->Count, Environment::NewLine );
      Console::ResetColor();
      store->Close();
      
      //Create an enumerator for moving through the collection.
      AsnEncodedDataEnumerator^ asne = asncoll->GetEnumerator();
      
      //You must execute a MoveNext() to get to the first item in the collection.
      asne->MoveNext();
      
      // Write out AsnEncodedData in the collection.
      Console::ForegroundColor = ConsoleColor::Blue;
      Console::WriteLine( L"First AsnEncodedData in the collection: {0}", asne->Current->Format(true) );
      Console::ResetColor();
      asne->MoveNext();
      Console::ForegroundColor = ConsoleColor::DarkBlue;
      Console::WriteLine( L"Second AsnEncodedData in the collection: {0}", asne->Current->Format(true) );
      Console::ResetColor();
      
      //Return index in the collection to the beginning.
      asne->Reset();
   }
   catch ( CryptographicException^ ) 
   {
      Console::WriteLine( L"Information could not be written out for this certificate." );
   }

   return 1;
}
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

class AsnEncodedDataSample
{
    static void Main()
    {		
        //The following example demonstrates the usage the AsnEncodedData classes.
        // Asn encoded data is read from the extensions of an X509 certificate.
        try
        {
            // Open the certificate store.
            X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
            X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
            X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
            // Select one or more certificates to display extensions information.
            X509Certificate2Collection scollection = 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.
            AsnEncodedDataCollection asncoll = new AsnEncodedDataCollection();
            for (int i = 0; i < scollection.Count; i++)
            {
                // Display certificate information.
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Certificate name: {0}", scollection[i].GetName());
                Console.ResetColor();
                // Display extensions information.
                foreach (X509Extension extension in scollection[i].Extensions)
                {
                    // Create an AsnEncodedData object using the extensions information.
                    AsnEncodedData asndata = new AsnEncodedData(extension.Oid, extension.RawData);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Extension type: {0}", extension.Oid.FriendlyName);
                    Console.WriteLine("Oid value: {0}",asndata.Oid.Value);
                    Console.WriteLine("Raw data length: {0} {1}", asndata.RawData.Length, Environment.NewLine);
                    Console.ResetColor();
                    Console.WriteLine(asndata.Format(true));
                    Console.WriteLine(Environment.NewLine);
                    // Add the AsnEncodedData object to the AsnEncodedDataCollection object.
                    asncoll.Add(asndata);
                }
                Console.WriteLine(Environment.NewLine);
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Number of AsnEncodedData items in the collection: {0} {1}", asncoll.Count, Environment.NewLine);
            Console.ResetColor();

            store.Close();
            //Create an enumerator for moving through the collection.
            AsnEncodedDataEnumerator asne = asncoll.GetEnumerator();
            //You must execute a MoveNext() to get to the first item in the collection.
            asne.MoveNext();
            // Write out AsnEncodedData in the collection.
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("First AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();

            asne.MoveNext();
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("Second AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();
            //Return index in the collection to the beginning.
            asne.Reset();
        }
        catch (CryptographicException)
        {
            Console.WriteLine("Information could not be written out for this certificate.");
        }
    }
}
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.
      Try
         ' 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()
            MsgBox(msg)

            ' 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
               MsgBox(msg)
        
               ' Add the AsnEncodedData object to the AsnEncodedDataCollection object.
               asncoll.Add(asndata)
            Next extension
         Next i
     msg = "Number of AsnEncodedData items in the collection: " & asncoll.Count
         MsgBox(msg)         
         store.Close()

         '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.
         asne.MoveNext()
         ' Write out AsnEncodedData in the collection.
     msg = "First AsnEncodedData in the collection: " & asne.Current.Format(True)
     MsgBox(msg)
    
         
         asne.MoveNext()
     msg = "Second AsnEncodedData in the collection: " & asne.Current.Format(True)
     MsgBox(msg)
        
         'Return index in the collection to the beginning.
         asne.Reset()
      Catch 
         MsgBox("Information could not be written out for this certificate.")
      End Try
   End Sub
End Class

Remarks

This constructor makes a copy of the specified AsnEncodedData instance.

Applies to

AsnEncodedData(Oid, Byte[])

Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs

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

public:
 AsnEncodedData(System::Security::Cryptography::Oid ^ oid, cli::array <System::Byte> ^ rawData);
public AsnEncodedData (System.Security.Cryptography.Oid? oid, byte[] rawData);
public AsnEncodedData (System.Security.Cryptography.Oid oid, byte[] rawData);
new System.Security.Cryptography.AsnEncodedData : System.Security.Cryptography.Oid * byte[] -> System.Security.Cryptography.AsnEncodedData
Public Sub New (oid As Oid, rawData As Byte())

Parameters

oid
Oid

An Oid object.

rawData
Byte[]

A byte array that contains Abstract Syntax Notation One (ASN.1)-encoded data.

Examples

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

#using <System.dll>
#using <System.Security.dll>

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::X509Certificates;

int main()
{
   
   //The following example demonstrates the usage of the AsnEncodedData classes.
   // Asn encoded data is read from the extensions of an X509 certificate.
   try
   {
      
      // Open the certificate store.
      X509Store^ store = gcnew X509Store( L"MY",StoreLocation::CurrentUser );
      store->Open( static_cast<OpenFlags>(OpenFlags::ReadOnly | OpenFlags::OpenExistingOnly) );
      X509Certificate2Collection^ collection = dynamic_cast<X509Certificate2Collection^>(store->Certificates);
      X509Certificate2Collection^ fcollection = dynamic_cast<X509Certificate2Collection^>(collection->Find( X509FindType::FindByTimeValid, DateTime::Now, false ));
      
      // Select one or more certificates to display extensions information.
      X509Certificate2Collection^ scollection = X509Certificate2UI::SelectFromCollection(fcollection, L"Certificate Select",L"Select certificates from the following list to get extension information on that certificate",X509SelectionFlag::MultiSelection);
      
      // Create a new AsnEncodedDataCollection object.
      AsnEncodedDataCollection^ asncoll = gcnew AsnEncodedDataCollection;
      for ( int i = 0; i < scollection->Count; i++ )
      {
         
         // Display certificate information.
         Console::ForegroundColor = ConsoleColor::Red;
         Console::WriteLine( L"Certificate name: {0}", scollection[i]->GetName() );
         Console::ResetColor();
         
         // Display extensions information.
         System::Collections::IEnumerator^ myEnum = scollection[i]->Extensions->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            X509Extension^ extension = safe_cast<X509Extension ^>(myEnum->Current);
            
            // Create an AsnEncodedData object using the extensions information.
            AsnEncodedData^ asndata = gcnew AsnEncodedData( extension->Oid,extension->RawData );
            Console::ForegroundColor = ConsoleColor::Green;
            Console::WriteLine( L"Extension type: {0}", extension->Oid->FriendlyName );
            Console::WriteLine( L"Oid value: {0}", asndata->Oid->Value );
            Console::WriteLine( L"Raw data length: {0} {1}", asndata->RawData->Length, Environment::NewLine );
            Console::ResetColor();
            Console::WriteLine( asndata->Format(true) );
            Console::WriteLine( Environment::NewLine );
            
            // Add the AsnEncodedData object to the AsnEncodedDataCollection object.
            asncoll->Add( asndata );
         }

         Console::WriteLine( Environment::NewLine );

      }
      Console::ForegroundColor = ConsoleColor::Red;
      Console::WriteLine( L"Number of AsnEncodedData items in the collection: {0} {1}", asncoll->Count, Environment::NewLine );
      Console::ResetColor();
      store->Close();
      
      //Create an enumerator for moving through the collection.
      AsnEncodedDataEnumerator^ asne = asncoll->GetEnumerator();
      
      //You must execute a MoveNext() to get to the first item in the collection.
      asne->MoveNext();
      
      // Write out AsnEncodedData in the collection.
      Console::ForegroundColor = ConsoleColor::Blue;
      Console::WriteLine( L"First AsnEncodedData in the collection: {0}", asne->Current->Format(true) );
      Console::ResetColor();
      asne->MoveNext();
      Console::ForegroundColor = ConsoleColor::DarkBlue;
      Console::WriteLine( L"Second AsnEncodedData in the collection: {0}", asne->Current->Format(true) );
      Console::ResetColor();
      
      //Return index in the collection to the beginning.
      asne->Reset();
   }
   catch ( CryptographicException^ ) 
   {
      Console::WriteLine( L"Information could not be written out for this certificate." );
   }

   return 1;
}
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

class AsnEncodedDataSample
{
    static void Main()
    {		
        //The following example demonstrates the usage the AsnEncodedData classes.
        // Asn encoded data is read from the extensions of an X509 certificate.
        try
        {
            // Open the certificate store.
            X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
            X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
            X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
            // Select one or more certificates to display extensions information.
            X509Certificate2Collection scollection = 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.
            AsnEncodedDataCollection asncoll = new AsnEncodedDataCollection();
            for (int i = 0; i < scollection.Count; i++)
            {
                // Display certificate information.
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Certificate name: {0}", scollection[i].GetName());
                Console.ResetColor();
                // Display extensions information.
                foreach (X509Extension extension in scollection[i].Extensions)
                {
                    // Create an AsnEncodedData object using the extensions information.
                    AsnEncodedData asndata = new AsnEncodedData(extension.Oid, extension.RawData);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Extension type: {0}", extension.Oid.FriendlyName);
                    Console.WriteLine("Oid value: {0}",asndata.Oid.Value);
                    Console.WriteLine("Raw data length: {0} {1}", asndata.RawData.Length, Environment.NewLine);
                    Console.ResetColor();
                    Console.WriteLine(asndata.Format(true));
                    Console.WriteLine(Environment.NewLine);
                    // Add the AsnEncodedData object to the AsnEncodedDataCollection object.
                    asncoll.Add(asndata);
                }
                Console.WriteLine(Environment.NewLine);
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Number of AsnEncodedData items in the collection: {0} {1}", asncoll.Count, Environment.NewLine);
            Console.ResetColor();

            store.Close();
            //Create an enumerator for moving through the collection.
            AsnEncodedDataEnumerator asne = asncoll.GetEnumerator();
            //You must execute a MoveNext() to get to the first item in the collection.
            asne.MoveNext();
            // Write out AsnEncodedData in the collection.
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("First AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();

            asne.MoveNext();
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("Second AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();
            //Return index in the collection to the beginning.
            asne.Reset();
        }
        catch (CryptographicException)
        {
            Console.WriteLine("Information could not be written out for this certificate.");
        }
    }
}
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.
      Try
         ' 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()
            MsgBox(msg)

            ' 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
               MsgBox(msg)
        
               ' Add the AsnEncodedData object to the AsnEncodedDataCollection object.
               asncoll.Add(asndata)
            Next extension
         Next i
     msg = "Number of AsnEncodedData items in the collection: " & asncoll.Count
         MsgBox(msg)         
         store.Close()

         '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.
         asne.MoveNext()
         ' Write out AsnEncodedData in the collection.
     msg = "First AsnEncodedData in the collection: " & asne.Current.Format(True)
     MsgBox(msg)
    
         
         asne.MoveNext()
     msg = "Second AsnEncodedData in the collection: " & asne.Current.Format(True)
     MsgBox(msg)
        
         'Return index in the collection to the beginning.
         asne.Reset()
      Catch 
         MsgBox("Information could not be written out for this certificate.")
      End Try
   End Sub
End Class

Applies to

AsnEncodedData(Oid, ReadOnlySpan<Byte>)

Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs

Initializes a new instance of the AsnEncodedData class from an object identifier (OID) and existing encoded data.

public:
 AsnEncodedData(System::Security::Cryptography::Oid ^ oid, ReadOnlySpan<System::Byte> rawData);
public AsnEncodedData (System.Security.Cryptography.Oid? oid, ReadOnlySpan<byte> rawData);
new System.Security.Cryptography.AsnEncodedData : System.Security.Cryptography.Oid * ReadOnlySpan<byte> -> System.Security.Cryptography.AsnEncodedData
Public Sub New (oid As Oid, rawData As ReadOnlySpan(Of Byte))

Parameters

oid
Oid

The object identifier for this data.

rawData
ReadOnlySpan<Byte>

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

Applies to

AsnEncodedData(String, Byte[])

Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs

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

public:
 AsnEncodedData(System::String ^ oid, cli::array <System::Byte> ^ rawData);
public AsnEncodedData (string oid, byte[] rawData);
new System.Security.Cryptography.AsnEncodedData : string * byte[] -> System.Security.Cryptography.AsnEncodedData
Public Sub New (oid As String, rawData As Byte())

Parameters

oid
String

A string that represents Oid information.

rawData
Byte[]

A byte array that contains Abstract Syntax Notation One (ASN.1)-encoded data.

Examples

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

#using <System.dll>
#using <System.Security.dll>

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::X509Certificates;

int main()
{
   
   //The following example demonstrates the usage of the AsnEncodedData classes.
   // Asn encoded data is read from the extensions of an X509 certificate.
   try
   {
      
      // Open the certificate store.
      X509Store^ store = gcnew X509Store( L"MY",StoreLocation::CurrentUser );
      store->Open( static_cast<OpenFlags>(OpenFlags::ReadOnly | OpenFlags::OpenExistingOnly) );
      X509Certificate2Collection^ collection = dynamic_cast<X509Certificate2Collection^>(store->Certificates);
      X509Certificate2Collection^ fcollection = dynamic_cast<X509Certificate2Collection^>(collection->Find( X509FindType::FindByTimeValid, DateTime::Now, false ));
      
      // Select one or more certificates to display extensions information.
      X509Certificate2Collection^ scollection = X509Certificate2UI::SelectFromCollection(fcollection, L"Certificate Select",L"Select certificates from the following list to get extension information on that certificate",X509SelectionFlag::MultiSelection);
      
      // Create a new AsnEncodedDataCollection object.
      AsnEncodedDataCollection^ asncoll = gcnew AsnEncodedDataCollection;
      for ( int i = 0; i < scollection->Count; i++ )
      {
         
         // Display certificate information.
         Console::ForegroundColor = ConsoleColor::Red;
         Console::WriteLine( L"Certificate name: {0}", scollection[i]->GetName() );
         Console::ResetColor();
         
         // Display extensions information.
         System::Collections::IEnumerator^ myEnum = scollection[i]->Extensions->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            X509Extension^ extension = safe_cast<X509Extension ^>(myEnum->Current);
            
            // Create an AsnEncodedData object using the extensions information.
            AsnEncodedData^ asndata = gcnew AsnEncodedData( extension->Oid,extension->RawData );
            Console::ForegroundColor = ConsoleColor::Green;
            Console::WriteLine( L"Extension type: {0}", extension->Oid->FriendlyName );
            Console::WriteLine( L"Oid value: {0}", asndata->Oid->Value );
            Console::WriteLine( L"Raw data length: {0} {1}", asndata->RawData->Length, Environment::NewLine );
            Console::ResetColor();
            Console::WriteLine( asndata->Format(true) );
            Console::WriteLine( Environment::NewLine );
            
            // Add the AsnEncodedData object to the AsnEncodedDataCollection object.
            asncoll->Add( asndata );
         }

         Console::WriteLine( Environment::NewLine );

      }
      Console::ForegroundColor = ConsoleColor::Red;
      Console::WriteLine( L"Number of AsnEncodedData items in the collection: {0} {1}", asncoll->Count, Environment::NewLine );
      Console::ResetColor();
      store->Close();
      
      //Create an enumerator for moving through the collection.
      AsnEncodedDataEnumerator^ asne = asncoll->GetEnumerator();
      
      //You must execute a MoveNext() to get to the first item in the collection.
      asne->MoveNext();
      
      // Write out AsnEncodedData in the collection.
      Console::ForegroundColor = ConsoleColor::Blue;
      Console::WriteLine( L"First AsnEncodedData in the collection: {0}", asne->Current->Format(true) );
      Console::ResetColor();
      asne->MoveNext();
      Console::ForegroundColor = ConsoleColor::DarkBlue;
      Console::WriteLine( L"Second AsnEncodedData in the collection: {0}", asne->Current->Format(true) );
      Console::ResetColor();
      
      //Return index in the collection to the beginning.
      asne->Reset();
   }
   catch ( CryptographicException^ ) 
   {
      Console::WriteLine( L"Information could not be written out for this certificate." );
   }

   return 1;
}
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

class AsnEncodedDataSample
{
    static void Main()
    {		
        //The following example demonstrates the usage the AsnEncodedData classes.
        // Asn encoded data is read from the extensions of an X509 certificate.
        try
        {
            // Open the certificate store.
            X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
            X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
            X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
            // Select one or more certificates to display extensions information.
            X509Certificate2Collection scollection = 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.
            AsnEncodedDataCollection asncoll = new AsnEncodedDataCollection();
            for (int i = 0; i < scollection.Count; i++)
            {
                // Display certificate information.
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Certificate name: {0}", scollection[i].GetName());
                Console.ResetColor();
                // Display extensions information.
                foreach (X509Extension extension in scollection[i].Extensions)
                {
                    // Create an AsnEncodedData object using the extensions information.
                    AsnEncodedData asndata = new AsnEncodedData(extension.Oid, extension.RawData);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Extension type: {0}", extension.Oid.FriendlyName);
                    Console.WriteLine("Oid value: {0}",asndata.Oid.Value);
                    Console.WriteLine("Raw data length: {0} {1}", asndata.RawData.Length, Environment.NewLine);
                    Console.ResetColor();
                    Console.WriteLine(asndata.Format(true));
                    Console.WriteLine(Environment.NewLine);
                    // Add the AsnEncodedData object to the AsnEncodedDataCollection object.
                    asncoll.Add(asndata);
                }
                Console.WriteLine(Environment.NewLine);
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Number of AsnEncodedData items in the collection: {0} {1}", asncoll.Count, Environment.NewLine);
            Console.ResetColor();

            store.Close();
            //Create an enumerator for moving through the collection.
            AsnEncodedDataEnumerator asne = asncoll.GetEnumerator();
            //You must execute a MoveNext() to get to the first item in the collection.
            asne.MoveNext();
            // Write out AsnEncodedData in the collection.
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("First AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();

            asne.MoveNext();
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("Second AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();
            //Return index in the collection to the beginning.
            asne.Reset();
        }
        catch (CryptographicException)
        {
            Console.WriteLine("Information could not be written out for this certificate.");
        }
    }
}
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.
      Try
         ' 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()
            MsgBox(msg)

            ' 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
               MsgBox(msg)
        
               ' Add the AsnEncodedData object to the AsnEncodedDataCollection object.
               asncoll.Add(asndata)
            Next extension
         Next i
     msg = "Number of AsnEncodedData items in the collection: " & asncoll.Count
         MsgBox(msg)         
         store.Close()

         '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.
         asne.MoveNext()
         ' Write out AsnEncodedData in the collection.
     msg = "First AsnEncodedData in the collection: " & asne.Current.Format(True)
     MsgBox(msg)
    
         
         asne.MoveNext()
     msg = "Second AsnEncodedData in the collection: " & asne.Current.Format(True)
     MsgBox(msg)
        
         'Return index in the collection to the beginning.
         asne.Reset()
      Catch 
         MsgBox("Information could not be written out for this certificate.")
      End Try
   End Sub
End Class

Applies to

AsnEncodedData(String, ReadOnlySpan<Byte>)

Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs
Source:
AsnEncodedData.cs

Initializes a new instance of the AsnEncodedData class from an object identifier (OID) and existing encoded data.

public:
 AsnEncodedData(System::String ^ oid, ReadOnlySpan<System::Byte> rawData);
public AsnEncodedData (string oid, ReadOnlySpan<byte> rawData);
new System.Security.Cryptography.AsnEncodedData : string * ReadOnlySpan<byte> -> System.Security.Cryptography.AsnEncodedData
Public Sub New (oid As String, rawData As ReadOnlySpan(Of Byte))

Parameters

oid
String

The object identifier for this data.

rawData
ReadOnlySpan<Byte>

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

Applies to