Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CryptAcquireContext fails with NTE_BAD_KEY_STATE

CryptAcquireContext fails with NTE_BAD_KEY_STATE

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadmindockersecurityjson
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajesh_Parameswaran
    wrote on last edited by
    #1

    Hi, My application fails after making a call to the Windows CryptAcquireContext API. I get the following error code NTE_BAD_KEY_STATE ( 0x8009000BL ). Code snippet and details below: //////////////////////////////////////////////////////////////////////////////// /* @func UINT32 | get_key | * Description: Get encryption key. In order to do this need to * acquire encryption context and hashing object. * *--------------------------------------------------------------------- */ //////////////////////////////////////////////////////////////////////////////// UINT32 get_key(TCHAR * szPassword, HCRYPTPROV * phProv, HCRYPTHASH * phHash, HCRYPTKEY * phKey) { ... ... // Get handle to user default provider. rc = CryptAcquireContext(phProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0); if(!rc) { lRet = GetLastError(); if (lRet == NTE_BAD_KEYSET) { // create default key container if (!CryptAcquireContext(phProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET)) { lRet = GetLastError(); } } } ... ... } The first call to CryptAcquireContext() here fails with NTE_BAD_KEY_STATE, and there isn't sufficient information available on MSDN bout the error code. All I got was that the error returned from the failing API suggests that the user password has changed since the private keys were encrypted. But there weren't any sort of user modifications done recently on my machine. The issue occurs on a Win2K3 HP server. But it seems to be happening only on one of my servers and works fine on others. Any ideas as to what might be going wrong here? I know that re-installing the OS here would fix this (cause it happened on another machine in the past and the only way out that time was re-installing the OS). But re-installing the OS here would mean a lot of work to be re-done at this point for me. Has anyone encountered such a problem in the past, if so, how was it resolved? Thanks in advance! - Benson

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups