关于usbkey验pin的代码

fox513 2009-11-19 11:00:48
我现在的做法,
第一
C_OpenSession(
m_pSlotList[0],
m_SessionFlags, //CKF_RW_SESSION | CKF_SERIAL_SESSION,
(CK_VOID_PTR)szApplication,
NULL_PTR,
&m_hSession);

通过m_hSession判断是否插入钥匙;

第二
HCRYPTPROV hCryptProv = NULL;
HCRYPTKEY hExPubKey = NULL;
BYTE a[128] = "CYBER";
DWORD lenth;
lenth = strlen((char *)a);
//获取密钥容器
if (!CryptAcquireContext(
&hCryptProv,
NULL,
TEST_CSP_NAME,
PROV_RSA_FULL,
NULL))
{
if (hCryptProv)
{
CryptReleaseContext(hCryptProv, 0);
}

if(hExPubKey)
{
CryptDestroyKey(hExPubKey);
}
return -1;
}
//获取密钥句柄

if (!CryptGetUserKey(
hCryptProv,
AT_KEYEXCHANGE,
&hExPubKey))
{
if (hCryptProv)
{
CryptReleaseContext(hCryptProv, 0);
}

if (hExPubKey)
{
CryptDestroyKey(hExPubKey);
}
return -2;
}

if (!CryptEncrypt(hExPubKey, 0, TRUE, 0, a, &lenth, 128))
{
cyber_error_f("auVerifyPinByCSP@LibPkcs11 加密失败");

if (hCryptProv)
{
CryptReleaseContext(hCryptProv, 0);
}
if (hExPubKey)
{
CryptDestroyKey(hExPubKey);
}
return -3;
}

if (!CryptDecrypt(hExPubKey, 0, TRUE, 0, a, &lenth))
{
cyber_error_f("auVerifyPinByCSP@LibPkcs11 错误PIN码");

if (hCryptProv)
{
CryptReleaseContext(hCryptProv, 0);
}
if (hExPubKey)
{
CryptDestroyKey(hExPubKey);
}
return -4;
}


if (hCryptProv)
{
CryptReleaseContext(hCryptProv, 0);
}
if (hExPubKey)
{
CryptDestroyKey(hExPubKey);
}
return 1;
}

如果成功放回1 验pin通过
现在的问题是插入钥匙第一次验通过以后,钥匙不拔,在调用上面的过程验pin就直接通过了 不会弹出输入pin码的窗口,是什么问题呢? 是不是CryptDecrypt(hExPubKey, 0, TRUE, 0, a, &lenth)中的TRUE要改成FALSE??
...全文
542 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lstc 2009-11-24
  • 打赏
  • 举报
回复
这个问题要咨询具体USBkey厂家的技术,看他们CSP在实现的时候做了哪些特殊处理
fox513 2009-11-19
  • 打赏
  • 举报
回复
还有 是在进行哪个地方的时候弹出验pin的对话框呢?

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧