?
Solved

Accessing private key with ASPNET

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
This article covers the basics of data encryption, what it is, how it works, and why it's important. If you've ever wondered what goes on when you "encrypt" data, you can look here to build a good foundation for your personal learning.
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

649 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