NerdyHearn
Home
Blog

Contact
Mailing List

Software

Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail

Sites
DocuTerminal
How Long For Me
My Music To Me
SaveMySerials
TypeCount

Blog
Twitter

NerdyHearn - Blog


<< Back To All Blogs

Enumerating a user secure certificate store in C#

Tuesday, July 14th, 2009

Reading a user's certificate store can be a very useful thing in C#, especially when dealing with anything at a low-level Windows usage, such as checking to see if the user on a domain has a valid certificate to use an Encrypted File System (EFS).

It is pretty straight-forward, so without further ado, here is how it is done:

X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);



foreach (X509Certificate2 cert in store.Certificates)

{

    // Cert thumbprint

    string thumbprint = cert.Thumbprint;



    // Cert serial number

    string serial = cert.SerialNumber;



    // Cert issuer

    string issuer = cert.Issuer;



    // Cert notbefore entry

    DateTime notbefore = cert.NotBefore;



    // Cert notafter entry

    DateTime notafter = cert.NotAfter;



    // Enumerate cert extensions, you can then cast them to their specific cert extension type if needed

    foreach (X509Extension ext in cert.Extensions)

    {

        string friendlyname = ext.Oid.FriendlyName;

        string value = ext.Oid.Value;

    }

}


That's all I have for now, pretty short entry, but a useful bit of code.

X509in' Tom Out.

Tags

CSharp

Related Blogs

Retrieving Text from Win32 SDK's GetLastError() in C#
Reading A Database Schema in SQLite with C#
Resizing Images in C#
Creating an MD5 String Extension method in C#
SharePoint RPC: Corrupted Binary Files

Comments

Currently no comments.

Add A Comment

Name:


URL:


Email Address: (not public, used to send notifications on further comments)


Comments:



Enter the text above, except for the 1st and last character:


NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. DocuTerminal - Online Filing Cabinet solution. Scan, search and archive your paper documents. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers My Music To Me - Stream your subsonic music collection to your Sonos wireless system TypeCount - Count how often you type across different computers! ServrTrackr - Monitor your SSL certificates, website uptime, and DNS configurations