?
Solved

Accessing private key with ASPNET

Posted on 2008-10-03
1
Medium Priority
?
1,082 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
The recent Petya-like ransomware attack served a big blow to hundreds of banks, corporations and government offices The Acronis blog takes a closer look at this damaging worm to see what’s behind it – and offers up tips on how you can safeguard your…
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 …
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 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