Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:51:38+00:00 2026-05-31T15:51:38+00:00

I wrote some code using the Microsoft CryptoAPI to calculate a SHA-1 and got

  • 0

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.

I narrowed down the failure to the CryptAcquireContext() call.

I did notice that a previous post talked about the XP faulty naming of “… (Prototype)” and it must be accounted for by using a WinXP specific macro MS_ENH_RSA_AES_PROV_XP.

I did the XP specific code modifications and it still doesn’t work. (The bResult returns 0 false on Win XP, all other platforms bResult returns 1 true.)

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.

Have I overlooked something to make it work on Windows XP?

I’ve pasted shortest possible example to illustrate the issue. I used VS2010 C++.

// based on examples from http://msdn.microsoft.com/en-us/library/ms867086.aspx

#include "windows.h"
#include "wincrypt.h"
#include <iostream>
#include <iomanip>  // for setw()

void main()
{
    BOOL bResult;
    HCRYPTPROV hProv;

    // Attempt to acquire a handle to the default key container.
    bResult = CryptAcquireContext(
        &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 << "line:  " << std::setw(4) << __LINE__ << ";  " << "bResult = " << bResult << std::endl;

    if (! bResult) {        // try Windows XP provider name
        bResult = CryptAcquireContext(
            &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 << "line:  " << std::setw(4) << __LINE__ << ";  " << "bResult = " << bResult << std::endl;
    }

    if (bResult)
        CryptReleaseContext(hProv, 0);
}

Windows 7 success:
enter image description here

Windows XP failure:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:51:39+00:00Added an answer on May 31, 2026 at 3:51 pm

    In your CryptAcquireContext code, it appears you are missing the parameter to get a context without a specific container set. You need to pass the CRYPT_VERIFYCONTEXT option in CryptAcquireContext.

    Windows 7 might be working around this.

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa379886(v=vs.85).aspx

    For further diagnosis, the results of GetLastError() would be requisite.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to C#. My boss asked me to wrote some code using
I wrote some code which monitors the output of Stopwatch using a tight loop.
I'm trying to access some C code via Python using ctypes, so I wrote
I am using Windows 2003 to write some PHP code. I use XAMPP Portable
i wrote some code to get Recent folders and files in C# by using
I am a beginner at using WPF. I have wrote some xaml code in
I'm trying to write some code using pure SQL using ASP.NET MVC. I assume
I'm trying to write some code using posix threads but I'm stuck from the
My company is beginning to write some code using Scala. I've been moved onto
I am using Eclipse (3.5.1), on Ubuntu 9.10 to write some C++ code. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.