Solved

Accessing private key with ASPNET

Posted on 2008-10-03
1
1,060 Views
Last Modified: 2010-05-18
I'm having some trouble importing and accessing a private key with the ASPNET user.
I know that when one imports a private key (.pfx file) manually, in windows, you get an option to mark the key as exportable.
Now, as far as I can tell, this is needed in order to retrieve that private key later on.

My problem comes in that I'm importing the private key in code, as the ASPNET user, and there doesn't seem to be a way to mark it as exportable, in the way that the windows certificate import wizard does.
To clarify, the import works just fine, but when I access the details on the now-imported certificate, there is no private key data.

This is the code I'm using to import the certificate, once I have already opened the .pfx file, with the correct password.

     public void ImportCertificate(X509Certificate2 cert, StoreName name, StoreLocation loc)
     {
         X509Store certStore = new X509Store(name, loc);
         StorePermission permission = new StorePermission(PermissionState.Unrestricted);
         permission.Flags = StorePermissionFlags.AddToStore;
         permission.Assert();
         certStore.Open(OpenFlags.ReadWrite);
         certStore.Add(cert);
         certStore.Close();
     }

Am I mucking up the permissions or the way I import this private key?
Or am I going about this the wrong way entirely?
0
Comment
Question by:djcheeky
1 Comment
 
LVL 13

Accepted Solution

by:
joechina earned 250 total points
Comment Utility
Try using this constructor when load pfx file to X509Certificate2
http://msdn.microsoft.com/en-us/library/ms148424.aspx

And with
Exportable and PersistKeySet flag
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Healthcare providers, insurance companies and other covered entities trust eFax Corporate to transmit their most sensitive documents. eFax Corporate can help your organization implement a HIPAA compliant cloud faxing solution.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now