-2

I've been playing around with CryptoAPI and everything was fine.

I've imported .PFX to the certificate store, got context, got CSP handle. Every function I've been using I've checked for the mistakes with GetLastError function. But when I'd called CryptGetUserKey with three arguments which are hCryptProv, dwKeySpec and pointer to UserKey, I got an error, but GetLastError call didn't show me anything but a random value like 2148073485 that means nothing I suppose.

How can I find out what is wrong?

OS - Windows 7 32b HP;

Programming language - C++;

IDE - MSVS2013 Ultimate.

Darth Hunterix
  • 1,484
  • 5
  • 27
  • 31
DKey
  • 1
  • 1
  • Look into using the `FormatMessage` function to convert `GetLastError` error codes to error messages. This will help you a lot. – annoying_squid Sep 12 '19 at 15:27

1 Answers1

1

GetLastError call didn't show me anything but a random value like 2148073485 that means nothing I suppose.

You fail WINAPI forever. It took me like five seconds to launch Calc.exe and convert it to hex: 8009000D, which looks like a perfectly valid error HRESULT.


Let's take some time to analyze it a bit more:

  • 8 is ERROR.
  • 9 is not 7, meaning it's not a regular Win32 error. A search in Visual C++ headers tells me 9 is FACILITY_SSPI.
  • If I search 8009000D in Visual C++ headers, I get this line: #define NTE_NO_KEY _HRESULT_TYPEDEF_(0x8009000DL) There, you have it, it's your error: NTE_NO_KEY.
  • MSDN is rather unhelpful, but Google shows some other questions about the NTE_NO_KEY error, such as this.
Community
  • 1
  • 1
Medinoc
  • 6,577
  • 20
  • 42