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

  • Home
  • SEARCH
  • 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 8791679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:52:35+00:00 2026-06-13T22:52:35+00:00

My C++ app needs to compute an MD5 hash value. Currently, it is done

  • 0

My C++ app needs to compute an MD5 hash value. Currently, it is done by OpenSSL, and I want to use WinAPI – to avoid dependencies on external libraries.

I wrote this code:

HCRYPTPROV hCryptProv = NULL;
HCRYPTHASH hHash = NULL;
HCRYPTHASH hHexHash = NULL;
HASH HA1;
HASHHEX HA1HEX;
DWORD data = HASHLEN;

// Get a handle to a cryptography provider context.
if(!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0))
{
    goto err;
}

// Acquire a hash object handle.
if(!CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash))
{
    goto err;
}

CryptHashData(hHash, (const BYTE *)str, strlen(str), 0);

now, the strange thing is that sometimes it works well, but in other times the CryptAcquireContext returns NTE_BAD_KEYSET error, that according to MSDN
:

The key container could not be opened. A common cause of this error is that the key container does not exist. To create a key container, call CryptAcquireContext using the CRYPT_NEWKEYSET flag. This error code can also indicate that access to an existing key container is denied. Access rights to the container can be granted by the key set creator by using CryptSetProvParam.

Blockquote

Now my questions are:

  1. If I call CryptSetProvParam, what exactly does it do? Is it normal that simple application changes the OS settings?
  2. Is there any less difficult way to compute MD5 in C++ windows?

I’ll appreciate if someone gives me good advice on what to do.
Thanks.

  • 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-06-13T22:52:36+00:00Added an answer on June 13, 2026 at 10:52 pm

    So, I found an example that does what you want at http://msdn.microsoft.com/en-us/library/aa382380%28VS.85%29.aspx

    Looking at their code, the difference I see is this line:

    Theirs: CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)

    Yours: CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)

    So, reading up on that flag, I find this information:

    CRYPT_VERIFYCONTEXT: This option is intended for applications that are using ephemeral keys, or applications that do not require access to persisted private keys, such as applications that perform only hashing, encryption, and digital signature verification. Only applications that create signatures or decrypt messages need access to a private key. In most cases, this flag should be set.

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa379886%28v=vs.85%29.aspx

    So, it looks like you are trying to get access to information you don’t need, and the request is denied. So the best option is to tell Windows you don’t need that information by including that flag.

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

Sidebar

Related Questions

My app needs to display a graphical representation of a value ranging from -1
I want to use Latent Semantic Analysis for a small app I'm building, but
My app needs feature to open iPhone/iPad Mail, contacts, Calendars settings panel and automatically
My app needs to have multiple screen e.g. one login page then another page
My app needs to install some files that can be edited by the application
My app needs to know the peer device’s IP address when my device is
My app needs to be set in iOS 5 Notification Center as 'alerts' and
My app needs many NSStrings containing differente hard coded web URLs, to be accessed
Our web app needs to be made PCI compliant, i.e. it must not store
Because the data size isn't little that my web app needs to load, it

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.