Use the AsnEncodedDataCollection class.
Imports System
Imports System.Security.Cryptography
Imports System.Security.Cryptography.X509Certificates
Class MainClass
Shared Sub Main()
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)
Dim scollection As X509Certificate2Collection = X509Certificate2UI.SelectFromCollection(fcollection, "Certificate Select", "Select certificates from the following list to get extension information on that certificate", X509SelectionFlag.MultiSelection)
Dim asncoll As New AsnEncodedDataCollection()
Dim i As Integer
For i = 0 To scollection.Count - 1
Console.WriteLine(scollection(i).GetName())
Dim extension As X509Extension
For Each extension In scollection(i).Extensions
Dim asndata As New AsnEncodedData(extension.Oid, extension.RawData)
Console.WriteLine("Extension type: " & extension.Oid.FriendlyName)
Console.WriteLine("Oid value: " & asndata.Oid.Value )
Console.WriteLine("Raw data length: " & asndata.RawData.Length)
Console.WriteLine(asndata.Format(True))
asncoll.Add(asndata)
Next extension
Next i
Console.WriteLine("Number of AsnEncodedData items in the collection: " & asncoll.Count)
store.Close()
End Sub
End Class
Related examples in the same category