关于usbkey验pin的代码

fox513 fox513 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我现在的做法,
第一
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??
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
fox513
其它技术问题 3,881 成员 9,044 内容