Solved

Accessing private key with ASPNET

Posted on 2008-10-03
1
1,074 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
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 …
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…

695 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