title: Reading an X.509 Certificate2 PrivateKey
body: <p>The following code is failing with the following message when trying to output the PrivateKey or PublicKey.  (The Thumbprint will output fine.):</p>
  
  <blockquote>
    <p>The process does not possess the 'SeSecurityPrivilege' privilege which is required for this operation.</p>
  </blockquote>
  
  <p>If I run as local administrator, it works.  How do I get around this issue.  </p>
  
  <p>fyi.. the certificate (pfx) is password protected--but not sure how to indicate that in this code snippet.</p>
  
  <pre><code>var certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
  certStore.Open(OpenFlags.ReadOnly);
  string thumbprint = "D80FB0BB6485B6A2DE647812C5AA72A8F7ABA14C";
  
  X509Certificate2Collection certCollection = certStore.Certificates.Find(
      X509FindType.FindByThumbprint,
      thumbprint, false);
  
  // Close the certificate store.
  certStore.Close();
  
  if (certCollection.Count == 0)
  {
      throw new SecurityException(string.Format(CultureInfo.InvariantCulture, "No certificate was found for thumbprint {0}", thumbprint));
  }
  Console.WriteLine(certCollection[0].PrivateKey);
  </code></pre>