Export (0) Print
Expand All

AsnEncodedDataEnumerator Class

Provides the ability to navigate through an AsnEncodedDataCollection object. This class cannot be inherited.

System.Object
  System.Security.Cryptography.AsnEncodedDataEnumerator

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

'Declaration
Public NotInheritable Class AsnEncodedDataEnumerator _
	Implements IEnumerator

The AsnEncodedDataEnumerator type exposes the following members.

  NameDescription
Public propertyCurrentGets the current AsnEncodedData object in an AsnEncodedDataCollection object.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodMoveNextAdvances to the next AsnEncodedData object in an AsnEncodedDataCollection object.
Public methodResetSets an enumerator to its initial position.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

This class implements the IEnumerator interface.

The following code example shows how to use the AsnEncodedDataEnumerator 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

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

Community Additions

ADD
Show:
© 2014 Microsoft