title: MS CryptoAPI doesn't work on Windows XP with CryptAcquireContext()
body: <p>I wrote some code using the Microsoft CryptoAPI to calculate a SHA-1 and got the compiled exe working on Windows 7, Win Server 2008, Win Server 2003.  However, when I run it under Windows XP SP3, it does not work.  </p>
  
  <p>I narrowed down the failure to the <code>CryptAcquireContext()</code> call.</p>
  
  <p>I did notice that <a href="https://stackoverflow.com/a/4523302">a previous post</a> talked about the XP faulty naming of "<em>… (Prototype)</em>" and it must be accounted for by using a WinXP specific macro MS_ENH_RSA_AES_PROV_XP.  </p>
  
  <p>I did the XP specific code modifications and it still doesn't work.  (The <code>bResult</code> returns 0 false on Win XP, all other platforms <code>bResult</code> returns 1 true.)</p>
  
  <p>I checked the MS_ENH_RSA_AES_PROV_XP with the actual key+string values I see in regedit.exe so everything looks like it's set up to work but no success.</p>
  
  <p>Have I overlooked something to make it work on Windows XP?</p>
  
  <p>I've pasted shortest possible example to illustrate the issue.  I used VS2010 C++.</p>
  
  <pre><code>// based on examples from http://msdn.microsoft.com/en-us/library/ms867086.aspx
  
  #include "windows.h"
  #include "wincrypt.h"
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;  // for setw()
  
  void main()
  {
      BOOL bResult;
      HCRYPTPROV hProv;
  
      // Attempt to acquire a handle to the default key container.
      bResult = CryptAcquireContext(
          &amp;hProv,            // Variable to hold returned handle.
          NULL,              // Use default key container.
          MS_DEF_PROV,       // Use default CSP.
          PROV_RSA_FULL,     // Type of provider to acquire.
          0);                // No special action.
      std::cout &lt;&lt; "line:  " &lt;&lt; std::setw(4) &lt;&lt; __LINE__ &lt;&lt; ";  " &lt;&lt; "bResult = " &lt;&lt; bResult &lt;&lt; std::endl;
  
      if (! bResult) {        // try Windows XP provider name
          bResult = CryptAcquireContext(
              &amp;hProv,            // Variable to hold returned handle.
              NULL,              // Use default key container.
              MS_ENH_RSA_AES_PROV_XP,  // Windows XP specific instead of using default CSP.
              PROV_RSA_AES,     // Type of provider to acquire.
              0);                // No special action.
          std::cout &lt;&lt; "line:  " &lt;&lt; std::setw(4) &lt;&lt; __LINE__ &lt;&lt; ";  " &lt;&lt; "bResult = " &lt;&lt; bResult &lt;&lt; std::endl;
      }
  
      if (bResult)
          CryptReleaseContext(hProv, 0);
  }
  </code></pre>
  
  <p>Windows 7 success:
  <img src="https://i.stack.imgur.com/TUxSG.png" alt="enter image description here"></p>
  
  <p>Windows XP failure:
  <img src="https://i.stack.imgur.com/J6u8b.png" alt="enter image description here"></p>