View Single Post
  #3 (permalink)  
Old 09-23-2009, 10:30 AM
jsunn jsunn is offline
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: May 2009
Location: Milwaukee, WI
Posts: 5
Reputation: 0
jsunn is on a distinguished programming path ahead
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 With Quote