AsnEncodedDataCollection Class

 

Represents a collection of AsnEncodedData objects. This class cannot be inherited.

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

System.Object
  System.Security.Cryptography.AsnEncodedDataCollection

Public NotInheritable Class AsnEncodedDataCollection
	Implements ICollection, IEnumerable

NameDescription
System_CAPS_pubmethodAsnEncodedDataCollection()

Initializes a new instance of the AsnEncodedDataCollection class.

System_CAPS_pubmethodAsnEncodedDataCollection(AsnEncodedData)

Initializes a new instance of the AsnEncodedDataCollection class and adds an AsnEncodedData object to the collection.

NameDescription
System_CAPS_pubpropertyCount

Gets the number of AsnEncodedData objects in a collection.

System_CAPS_pubpropertyIsSynchronized

Gets a value that indicates whether access to the AsnEncodedDataCollection object is thread safe.

System_CAPS_pubpropertyItem(Int32)

Gets an AsnEncodedData object from the AsnEncodedDataCollection object.

System_CAPS_pubpropertySyncRoot

Gets an object that can be used to synchronize access to the AsnEncodedDataCollection object.

NameDescription
System_CAPS_pubmethodAdd(AsnEncodedData)

Adds an AsnEncodedData object to the AsnEncodedDataCollection object.

System_CAPS_pubmethodCopyTo(AsnEncodedData(), Int32)

Copies the AsnEncodedDataCollection object into an array.

System_CAPS_pubmethodEquals(Object)

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

System_CAPS_pubmethodGetEnumerator()

Returns an AsnEncodedDataEnumerator object that can be used to navigate the AsnEncodedDataCollection object.

System_CAPS_pubmethodGetHashCode()

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

System_CAPS_pubmethodGetType()

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

System_CAPS_pubmethodRemove(AsnEncodedData)

Removes an AsnEncodedData object from the AsnEncodedDataCollection object.

System_CAPS_pubmethodToString()

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

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection.CopyTo(Array, Int32)

Copies the AsnEncodedDataCollection object into an array.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable.GetEnumerator()

Returns an AsnEncodedDataEnumerator object that can be used to navigate the AsnEncodedDataCollection object.

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast(Of TResult)()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType(Of TResult)()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

This class implements the ICollection interface.

The following code example shows how to use the AsnEncodedDataCollection 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.
      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 '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
Show: