"Keyset does not exist" after change password

From: danc (anonymous_at_discussions.microsoft.com)
Date: 02/25/04


Date: Wed, 25 Feb 2004 08:11:07 -0800

I am reposting this question in a slightly different way hoping that somebody has experienced this before...

My customer changes their domain password as follows:
1. logs onto network
2. Ctrl+Alt+Del, choosing Change password tab
3. Changes the password
4. Logs off computer and re-logs on using same account
5. My application then returns "Keyset does not exist" when it calls CryptAcquireContext to open my keyset.

Here is relevant parts of my code:

// Attempt to acquire a context with the key container
CString m_KeyContainerName = "MyAppsContainer";
HCRYPTPROV m_hCsp;
if ( !::CryptAcquireContext( &m_hCsp, m_KeyContainerName, MS_ENHANCED_PROV, PROV_RSA_FULL, 0 ) ) {
   // Could not find the key container.
   // Try to create it now
   if ( !::CryptAcquireContext( &m_hCsp, m_KeyContainerName, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET ) ) {
      // Could not create a key container
      }
   }

Whenever the user changes their domain password, the first call to CryptAcquireContext(0) returns 0x80090016 "keyset does not exist" and the call to CryptAcquireContext( CRYPT_NEWKEYSET) returns 0x8009000F "object already exists" (which does not make sense since the previous call said it didn't exist, assuming the object in question is the keyset). The way the application is designed, each user is not an admin and gets his/her own unique key container.

Any help would be greatly appreciated.

Thanks in advance,

Dan