title: Fighting with certificates: Access was not successfully obtained for the private key
body: <p>I work in company with many servers and Pcs for developers. Servers are win2003, PC developers Windows XP.</p>
  
  <p>In a server Win2003 named preiis01, in preproduction environment, other people in company install a client certificate using any other user (unknown user for me) for logging in server preiis01.</p>
  
  <p>I use my user "domainCompany\myuser" for log in server preiis01 (using Terminal Server, Remote Desktop for Windows XP).</p>
  
  <p>in preiis01,</p>
  
  <p>I execute mmc -> Snap in -> Certificates for Local Machine. In node -> Personal -> Certificates, I have seen the client certificate:</p>
  
  <p>Issued To
  ENTIDAD COMPANY INSURE SA - CIF A93 - NOMBRE SURNAME1 NAME1</p>
  
  <p>Issued By
  FNMT Clase 2 CA</p>
  
  <p>In properties of certificate, I have seen thumbprint: "93 bc a4 ad 58 c9 3c af 8b eb 0b 2f 86 c7 9d 81 70 a6 c4 13"</p>
  
  <p>Now, I execute this commands:</p>
  
  <p>1.) FindPrivateKey My LocalMachine -n "CN=ENTIDAD COMPANY INSURE SA - CIF A93 - NOMBRE SURNAME1 NAME1" -a</p>
  
  <p>and I get this error:</p>
  
  <p><em>FindPrivateKey failed for the following reason:
  No certificates with key 'CN=ENTIDAD COMPANY INSURE SA - CIF A93 - NOMBRE SURNAME1 NAME1
  ' found in the store.</em></p>
  
  <p>2.) FindPrivateKey My LocalMachine -t "93 bc a4 ad 58 c9 3c af 8b eb 0b 2f 86 c7 9d 81 70 a6 c4 13" –c</p>
  
  <p>and I get this:</p>
  
  <p>*FindPrivateKey helps user to find the location of the Private Key file of a X.50
  9 Certificate.</p>
  
  <p>Usage: FindPrivateKey   [{ {-n } | {-t } } [-f | -d | -a]]</p>
  
  <pre><code>   &lt;subjectName&gt; subject name of the certificate
  
     &lt;thumbprint&gt;  thumbprint of the certificate (use certmgr.exe to get it)
  
     -f            output file name only
  
     -d            output directory only
  
     -a            output absolute file name
  </code></pre>
  
  <p>e.g. FindPrivateKey My CurrentUser -n "CN=John Doe"</p>
  
  <p>e.g. FindPrivateKey My LocalMachine -t "03 33 98 63 d0 47 e7 48 71 33 62 64 76 5
  c 4c 9d 42 1d 6b 52" -c*</p>
  
  <p>3.) winhttpcertcfg.exe -l -c LOCAL_MACHINE\My -s "ENTIDAD COMPANY INSURE SA - CIF A93 - NOMBRE SURNAME1 NAME1"</p>
  
  <p>and I get this error:</p>
  
  <blockquote>
    <p>Microsoft (R) WinHTTP Certificate
    Configuration Tool Copyright (C)
    Microsoft Corporation 2001. Matching
    certificate: </p>
    
    <p>CN=ENTIDAD COMPANY INSURE SA - CIF A93 - NOMBRE SURNAME1 NAME1</p>
    
    <p>OU=700012436</p>
    
    <p>OU=FNMT Clase 2 CA</p>
    
    <p>O=FNMT </p>
    
    <p>C=ES </p>
    
    <p>Error:</p>
    
    <p>Access was not successfully obtained for the private key. This can only be done by the user who installed the certificate.</p>
  </blockquote>
  
  <p><strong>Access was not successfully obtained for the private key.</strong></p>
  
  <p>Any suggestions ??</p>
  
  <p>Updated: by Marcel Roma (social msdn forums)</p>
  
  <p>Most likely the certificate was installed by some other person in your company (e.g. administrator). Only that person has access to the private key of the certificate. Download the FindPrivateKey tool, ask the administrator to execute it to find out the directory where the private key file was saved, and let him set the needed rights so that the process can access the file.</p>
  
  <p>There are also some reports about Windows XP failing to extract the private key from the file due to encoding issues: </p>
  
  <p><a href="http://blogs.msdn.com/b/alejacma/archive/2010/01/11/winhttpcertcfg-tool-cannot-access-private-key-of-a-certificate.aspx" rel="nofollow">http://blogs.msdn.com/b/alejacma/archive/2010/01/11/winhttpcertcfg-tool-cannot-access-private-key-of-a-certificate.aspx</a> </p>
  
  <p>Update:</p>
  
  <p>User in domain "domainCompany\Pre_Certificado" install Certificate in Store Local Machine.</p>
  
  <p>domainCompany\Pre_Certificado is Administrator, in IIS_WPG group, has Local Policies: “Log on as Service“</p>
  
  <p>I configure AppPool Identity in IIS 6.0 for : domainCompany\Pre_Certificado</p>
  
  <p>ASP.NET application executes using the identity :: domainCompany\Pre_Certificado</p>
  
  <p>I recycle AppPool and execute application, I get System.Security.Cryptography.CryptographicException: Cannot find the certificate and private key for decryption</p>
  
  <p>If I test again, log in session in server IIS, using domainCompany\Pre_Certificado user, I call page in ASP.NET application and all is OK.</p>
  
  <p>(note: log in server IIS using Terminal Server)</p>
  
  <p>But if log off session in server IIS (user: domainCompany\Pre_Certificado), I get the same error:</p>
  
  <p>System.Security.Cryptography.CryptographicException: Cannot find the certificate and private key for decryption</p>
  
  <p>Any suggestions ??</p>