I've tried out the sample program at MSDN that demonstrates how a hash can be signed and a hash signature verified. But when I execute the program, I get the following output:
CSP context acquired.
An error occurred in running the program.
Error during CryptGetUserKey for signkey.
Error number 8009000d.
Program terminating.
8009000d is the numeric error code for NTE_NO_KEY. Does anyone have an idea why the program fails in this way? I'm on Windows 7.
Apparently there is no key in the context you've aquired.
You can change slightly this example, by combining it with another microsoft example one about context acqusition and key generation. You have simply to add code for generateing keys if these are missing:
...
if (CryptGetUserKey(hProv, AT_SIGNATURE, &hKey)) { // if block unchanged
printf("The signature key has been acquired. \n");
}
else if (GetLastError() == NTE_NO_KEY) { // insert processing of missing keys
if (CryptGenKey(
hProv,
AT_SIGNATURE,
0,
&hKey)) {
printf("Created a signature key pair.\n");
}
else {
MyHandleError("Error during creation of new signature key.");
}
}
else { // The original else part will handle other errors
MyHandleError("Error during CryptGetUserKey for signkey.");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With