我在MSDN试用了示例程序,演示了如何对哈希进行签名并验证哈希签名。但是当我执行程序时,我得到以下输出:
CSP context acquired.
An error occurred in running the program.
Error during CryptGetUserKey for signkey.
Error number 8009000d.
Program terminating.
8009000d是NTE_NO_KEY的数字错误代码。有没有人知道为什么程序以这种方式失败?我在Windows 7上。
答案 0 :(得分:3)
显然,你所获得的背景中没有关键。
您可以稍微更改此示例,方法是将其与另一个关于上下文获取和密钥生成的Microsoft示例相结合。如果缺少密钥,您只需添加用于生成密钥的代码:
...
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.");
}