关于CryptAPI函数的一个小疑点
关于CryptAPI函数的一个小问题
[code=C/C++][/code]if(CryptGetUserKey(
hProv,
AT_SIGNATURE,
&hKey))
{
printf("The signature key has been acquired. \n");
}
else
{
MyHandleError("Error during CryptGetUserKey for signkey.");
}
//-------------------------------
// Export the public key. Here the public key is exported to a
// PUBLICKEYBOLB so that the receiver of the signed hash can
// verify the signature. This BLOB could be written to a file and
// sent to another user.
if(CryptExportKey(
hKey,
NULL,
PUBLICKEYBLOB,
0,
NULL,
&dwBlobLen))
{
printf("Size of the BLOB for the public key determined. \n");
}
else
{
MyHandleError("Error computing BLOB length.");
}
这是在msdn关于签名的一段代码,不是很明白这里的hKey到底是什么密钥?按它的注释是签名密钥,但下面又为什么要CryptExportKEY呢?刚开始学,看了半天也没看懂这个意思
------解决方案--------------------
这个涉及到了私钥加密公钥解密的证书认证过程。
lz去了解下 公钥密码学和数字签名相关知识吧。不是三言两语能说的很清楚的
[code=C/C++][/code]if(CryptGetUserKey(
hProv,
AT_SIGNATURE,
&hKey))
{
printf("The signature key has been acquired. \n");
}
else
{
MyHandleError("Error during CryptGetUserKey for signkey.");
}
//-------------------------------
// Export the public key. Here the public key is exported to a
// PUBLICKEYBOLB so that the receiver of the signed hash can
// verify the signature. This BLOB could be written to a file and
// sent to another user.
if(CryptExportKey(
hKey,
NULL,
PUBLICKEYBLOB,
0,
NULL,
&dwBlobLen))
{
printf("Size of the BLOB for the public key determined. \n");
}
else
{
MyHandleError("Error computing BLOB length.");
}
这是在msdn关于签名的一段代码,不是很明白这里的hKey到底是什么密钥?按它的注释是签名密钥,但下面又为什么要CryptExportKEY呢?刚开始学,看了半天也没看懂这个意思
------解决方案--------------------
这个涉及到了私钥加密公钥解密的证书认证过程。
lz去了解下 公钥密码学和数字签名相关知识吧。不是三言两语能说的很清楚的