+ Reply to Thread
Results 1 to 3 of 3

Thread: Help getting x509 certificate properties

  1. #1
    jsunn is offline VB.NET Forum Newbie jsunn is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    May 2009
    Location
    Milwaukee, WI
    Posts
    5
    Reputation
    0

    Default Help getting x509 certificate properties

    Hi, I'm a pretty obvious newcomer to .net / VB. We have lots of administrative scripts that use CAPICOM to manage our EFS certificates on our corporate workstations. With Windows 7 CAPICOM is no longer supported so I'm trying to make it work with the X509Certificate2 class. We are trying to convert code that opens a users certificate store (CURRENT USER STORE), loops through the certificates in the collection, and gets determines if the certificate is exportable or not. To determine whether the certificate is exportable or not the CspKeyContainerInfo.Exportable Property must be accessed but I'm having trouble making the connection on how to access it as I loop through the certificates in the collection. here is the code I have so far below. Its just a form with a button, it loops through the current users certificates, showing the thumbprint for each. I would also like to know if the certificate is exportable as well. I think that the certificate container must be retrieved using CspKeyContainerInfo, but not sure how to make it work.

    I've been looking at these MSDN pages as a reference:
    CSPKeyContainerInfo

    RsaCryptoServiceProvider.CspKeyContainerinfo


    here is the code so far:
    Code:
    Imports System
    Imports System.Security.Cryptography
    Imports System.Security.Cryptography.X509Certificates
    Imports System.Text
    Imports System.IO
    Public Class Form1
     
     
     
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
     
            'Instantiate the Store / The store name is My, location is current user store
            Dim store As New X509Store("MY", StoreLocation.CurrentUser)
            'Open the stor
            store.Open(OpenFlags.ReadWrite)
            'Use the X509CertificateCollection class to get the certificates from the my store into a collection
            Dim collection As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection)
            'Declare x509 as the certificate object
     
            Dim x509 As New X509Certificate2
     
     
            'Loop through the certificates in the store, one by one
            '------------
            
     
            For Each x509 In collection
                
     
                'Show the thumbprint for each certificate in the users store
                MsgBox(x509.Thumbprint)
                'Code here to analyze whether certificate is exportable or not
     
     
            Next x509
     
            store.Close()
    End Sub

  2. #2
    jsunn is offline VB.NET Forum Newbie jsunn is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    May 2009
    Location
    Milwaukee, WI
    Posts
    5
    Reputation
    0

    Default

    Bump- Anyone got an idea on this one?

  3. #3
    jsunn is offline VB.NET Forum Newbie jsunn is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    May 2009
    Location
    Milwaukee, WI
    Posts
    5
    Reputation
    0

    Default

    Okay, I'll answer this myself since it might be useful to someone else:
    Code:
    Imports System
    Imports System.Security.Cryptography
    Imports System.Security.Cryptography.X509Certificates
    Imports System.Text
    Imports System.IO
    Public Class Form1
     
     
     
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
     
            'Instantiate the Store / The store name is My, location is current user store
            Dim store As New X509Store("MY", StoreLocation.CurrentUser)
            'Open the store
            store.Open(OpenFlags.ReadWrite)
            'Use the X509CertificateCollection class to get the certificates from the my store into a collection
            Dim rsa As New RSACryptoServiceProvider()
            Dim keyInfo As CspKeyContainerInfo
            Dim collection As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection)
            'Declare x509 as the certificate object
     
            Dim x509 As New X509Certificate2
     
     
            'Loop through the certificates in the store, one by one
            '------------
            
     
            For Each x509 In collection
                
                rsa = DirectCast(x509Cert.PrivateKey, RSACryptoServiceProvider)
                keyInfo = rsa.CspKeyContainerInfo
    
                'Show the thumbprint for each certificate in the users store
                MsgBox("Thumbprint:" & x509.Thumbprint & " Exportable:" & keyInfo.Exportable)
               
     
     
            Next x509
     
            store.Close()
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts