Solved

Accessing private key with ASPNET

Posted on 2008-10-03
1
1,070 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
joechina earned 250 total points
ID: 22634805
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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