title: CRYPT_E_NOT_FOUND when importing certificate
body: <p>I'm trying to automate the process of generating a certificate signing request and then importing the response from the CA on a Windows Server 2012 R2 server to use as a cert for a SSL binding in IIS. I'm able to generate the CSR which I then provide to the security team which then provides me with a response to then import but am having troubles getting it to import.</p>
  
  <p>This server is in a workgroup. Thought I'd mention that so no AD enrollment policy.</p>
  
  <p>Here's my process:</p>
  
  <ol>
  <li>Generate a CSR with certreq.exe on the server in question. An INF file is generated that looks something like this:</li>
  </ol>
  
  <blockquote>
  <pre><code>[Version]
  Signature = "$Windows NT$"
  [NewRequest]
  Subject = "C=US,S=California,L=City,O=Company,OU=IT,CN=hostname"
  Exportable = TRUE
  KeyLength = 2048
  KeySpec = 1
  KeyUsage = 0xa0
  MachineKeySet = True
  ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
  ProviderType = 12
  Silent = True
  SMIME = False
  RequestType = PKCS10
  </code></pre>
  </blockquote>
  
  <p>This INF file then gets turned into the CSR .req file by doing this:</p>
  
  <pre><code>certreq.exe -new "C:\inffile.inf" "C:\certreq.req"
  </code></pre>
  
  <p>The REQ file gets sent to the security team and they give me back a .CER file, which, when imported manually, actually adds three certificates from Digicert. The certificate I expect and what looks to be some intermediate CAs.</p>
  
  <p>Here's what that looks like when imported via the MMC Certificates snapin.</p>
  
  <p><a href="https://i.stack.imgur.com/ZiIyi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZiIyi.png" alt="enter image description here"></a></p>
  
  <p>If I import the certificate via the MMC like this it doesn't show up in the IIS manager under Server Certificates so I looked a little deeper. I tried to complete the certificate signing request via the the IIS manager like this and the cert shows up and I'm happy.</p>
  
  <p><a href="https://i.stack.imgur.com/hbM82.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hbM82.png" alt="enter image description here"></a></p>
  
  <p>However, I can't use the GUI since I'm using a script. </p>
  
  <p>I confirm that the request is in Certificate Enrollment Requests with the private key.</p>
  
  <p><a href="https://i.stack.imgur.com/n1gSF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n1gSF.png" alt="enter image description here"></a></p>
  
  <p>I confirm that the public key of the CSR and the p7b I got back provided are the same.</p>
  
  <pre><code>certutil -dump issuedcert.cer
  certutil -dump certreq.req
  </code></pre>
  
  <p><strong>PROBLEM:</strong> I exported the CSR from Certificate Enrollment Requests and looked at the public key. It was NOT the same as the one in issuedcert.cer.  It looks like this is the problem but why?</p>
  
  <p>I then try to use certreq.exe to accept the response and it doesn't work.</p>
  
  <pre><code>certreq.exe -accept -machine "C:\issuedcert.cer"
  </code></pre>
  
  <p>Almost done, but no.  I continually receive this error message:</p>
  
  <p><a href="https://i.stack.imgur.com/3hIa8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3hIa8.png" alt="enter image description here"></a></p>