AsnEncodedDataCollection Třída

Definice

Představuje kolekci AsnEncodedData objektů.Represents a collection of AsnEncodedData objects. Tuto třídu nelze zdědit.This class cannot be inherited.

public ref class AsnEncodedDataCollection sealed : System::Collections::ICollection
public sealed class AsnEncodedDataCollection : System.Collections.ICollection
type AsnEncodedDataCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class AsnEncodedDataCollection
Implements ICollection
Dědičnost
AsnEncodedDataCollection
Implementuje

Příklady

Následující příklad kódu ukazuje, jak použít AsnEncodedDataCollection třídu.The following code example shows how to use the AsnEncodedDataCollection 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

Poznámky

Tato třída implementuje ICollection rozhraní.This class implements the ICollection interface.

Konstruktory

AsnEncodedDataCollection()

Inicializuje novou instanci AsnEncodedDataCollection třídy.Initializes a new instance of the AsnEncodedDataCollection class.

AsnEncodedDataCollection(AsnEncodedData)

Inicializuje novou instanci AsnEncodedDataCollection třídy a přidá AsnEncodedData objekt do kolekce.Initializes a new instance of the AsnEncodedDataCollection class and adds an AsnEncodedData object to the collection.

Vlastnosti

Count

Získá počet AsnEncodedData objektů v kolekci.Gets the number of AsnEncodedData objects in a collection.

IsSynchronized

Získá hodnotu, která označuje, zda je přístup k objektu bezpečný pro přístup z AsnEncodedDataCollection více vláken.Gets a value that indicates whether access to the AsnEncodedDataCollection object is thread safe.

Item[Int32]

Získá AsnEncodedData objekt z AsnEncodedDataCollection objektu.Gets an AsnEncodedData object from the AsnEncodedDataCollection object.

SyncRoot

Získává objekt, který lze použít k synchronizaci přístupu k AsnEncodedDataCollection objektu.Gets an object that can be used to synchronize access to the AsnEncodedDataCollection object.

Metody

Add(AsnEncodedData)

Přidá AsnEncodedData objekt k AsnEncodedDataCollection objektu.Adds an AsnEncodedData object to the AsnEncodedDataCollection object.

CopyTo(AsnEncodedData[], Int32)

Zkopíruje AsnEncodedDataCollection objekt do pole.Copies the AsnEncodedDataCollection object into an array.

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.Determines whether the specified object is equal to the current object.

(Zděděno od Object)
GetEnumerator()

Vrátí AsnEncodedDataEnumerator objekt, který lze použít k procházení AsnEncodedDataCollection objektu.Returns an AsnEncodedDataEnumerator object that can be used to navigate the AsnEncodedDataCollection object.

GetHashCode()

Slouží jako výchozí funkce hash.Serves as the default hash function.

(Zděděno od Object)
GetType()

Získá Type aktuální instanci.Gets the Type of the current instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří kopii aktuálního seznamu Object .Creates a shallow copy of the current Object.

(Zděděno od Object)
Remove(AsnEncodedData)

Odebere AsnEncodedData objekt z AsnEncodedDataCollection objektu.Removes an AsnEncodedData object from the AsnEncodedDataCollection object.

ToString()

Vrátí řetězec, který představuje aktuální objekt.Returns a string that represents the current object.

(Zděděno od Object)

Explicitní implementace rozhraní

ICollection.CopyTo(Array, Int32)

Zkopíruje AsnEncodedDataCollection objekt do pole.Copies the AsnEncodedDataCollection object into an array.

ICollection.IsSynchronized

Načte hodnotu, která označuje, jestli se má synchronizovat přístup k aplikaci (bezpečné pro přístup z ICollection více vláken).Gets a value indicating whether access to the ICollection is synchronized (thread safe).

ICollection.SyncRoot

Získává objekt, který lze použít k synchronizaci přístupu k ICollection .Gets an object that can be used to synchronize access to the ICollection.

IEnumerable.GetEnumerator()

Vrátí AsnEncodedDataEnumerator objekt, který lze použít k procházení AsnEncodedDataCollection objektu.Returns an AsnEncodedDataEnumerator object that can be used to navigate the AsnEncodedDataCollection object.

Metody rozšíření

Cast<TResult>(IEnumerable)

Přetypování prvky IEnumerable na zadaný typ.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filtruje prvky IEnumerable založené na zadaném typu.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Povoluje paralelní zpracování dotazu.Enables parallelization of a query.

AsQueryable(IEnumerable)

Převede IEnumerable na IQueryable .Converts an IEnumerable to an IQueryable.

Platí pro