微软MSDN有这样一段DEMO代码,演示HASH签名。HCRYPTPROV hProv;
BYTE *pbBuffer= (BYTE *)"The data that is to be hashed and signed.";
DWORD dwBufferLen = strlen((char *)pbBuffer)+1;
HCRYPTHASH hHash;
HCRYPTKEY hKey;
HCRYPTKEY hPubKey;
BYTE *pbKeyBlob;        
BYTE *pbSignature;
DWORD dwSigLen;
DWORD dwBlobLen;
LPTSTR szDescription = "Test Data Description";//--------------------------------------------------------------------
// Acquire a CSP. if(CryptAcquireContext(
   &hProv, 
   NULL, 
   NULL, 
   PROV_RSA_FULL, 
   0)) 
{
     printf("CSP context acquired.\n");
}
else
{
     HandleError("Error during CryptAcquireContext.");
}
//--------------------------------------------------------------------
// Get the public at signature key. This is the public key
// that will be used by the receiver of the hash to verify
// the signature. In situations where the receiver could obtain the
// sender's public key from a certificate, this step would not be
// needed.if(CryptGetUserKey(   
   hProv,    
   AT_SIGNATURE,    
   &hKey)) 
{
    printf("The signature key has been acquired. \n");
}
else
{
    HandleError("Error during CryptGetUserKey for signkey.");
}
=====================================================我在使用时,调用CryptGetUserKey函数总是错误,错误代码是NTE_NO_KEY,大意是说AT_SIGNATURE参数所要求的KEY不存在,不知如何解决,请有经验的兄弟指点

解决方案 »

  1.   

    //--------------------------------------------------------------------
    // Get the public at signature key. This is the public key
    // that will be used by the receiver of the hash to verify
    // the signature. In situations where the receiver could obtain the
    // sender's public key from a certificate, this step would not be
    // needed.
    呵呵,微软的注释给你说的很明白啊,你返回的错误是NTE_NO_KEY就是说签名的密钥不存在,微软在注释中已经告诉你了In situations where the receiver could obtain the sender's public key from a certificate, this step would not be needed.
    你没有key就需要做这一步