CryptographicException: Access denied - How to give access on User store?
<p>I am trying to load a certificate from a pfx file in a WPF application and it gives me an access denied error. </p>

<pre><code>using (FileStream stream = System.IO.File.OpenRead(certificatePath))
{
    using (BinaryReader reader = new BinaryReader(stream))
    {
        buffer = reader.ReadBytes((int)stream.Length);
    }
}

X509Certificate2 certificate = new X509Certificate2(buffer, password);
</code></pre>

<blockquote>
  <p>System.Security.Cryptography.CryptographicException: Access denied.<br>
  at
  System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32
  hr)    at
  System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[]
  rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet,
  SafeCertContextHandle&amp; pCertCtx)    at
  System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[]
  rawData, Object password, X509KeyStorageFlags keyStorageFlags)    at
  System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[]
  rawData, String password)    at
  HelloWorld.HelloClient.Models.Infrastructure.ReadCertificateFromPfxFile(String
  certificatePath, String password)</p>
</blockquote>

<p>The last line in snippet is causing an exception, and if I run it as an administrator it works fine. The issue seems to be the default constructor of X509Certificate2 tries to put private key in the user store. I am not using web application. <a href="https://stackoverflow.com/questions/9951729/x509certificate-constructor-exception">this</a> post doesn't resolve my issue. I think the current user might not have access to his own private key store. But how can I give that access? </p>