如何在cryptocki中重命名容器名称



我写了一些代码,在令牌中写入公钥和私钥的密钥对。我从密钥对创建pkcs10,然后从中生成证书文件。证书文件将插入令牌中。这一切都成功运行,但不知何故,CAPI或Internet Explorer无法读取证书。如果我插入一个p12文件,它运行起来不会太麻烦。我怀疑CKA_LABEL和CKA_ID是罪魁祸首。在p12中,所有东西都使用相同的名称约定。来自容器、公钥、私钥和证书。然而,在我的方法中,容器名称看起来像是自动生成的。如何将其转换为与CKA_ID相同?下面是我在生成保存在容器中的密钥对时的代码。

rv = g_pFunctionList->C_GenerateKeyPair(hSession,
&ck_gen_ecc,
tPubKey, sizeof(tPubKey) / sizeof(CK_ATTRIBUTE),
tPrvKey, sizeof(tPrvKey) / sizeof(CK_ATTRIBUTE),
&pkcs11_hPubKey, &pkcs11_hPrvKey); 

它保存在类似的容器名称中

cont_4440xxxxxxxx

如何更改与CKA_ID完全相同的容器名称?有人能帮忙吗?

如果您的cryptocki库允许,您可以通过调用C_SetAttributeValue函数设置所有对象的新属性来重命名它们。

在你的情况下,它可能看起来像这样:

CK_ATTRIBUTE atAttr[2];
atAttr[0].type = CKA_LABEL;
atAttr[0].pValue = pLabelValue;    // <-- pass here new Label value pointer
atAttr[0].ulValueLen = ulLabelLen; // <-- pass here new Label length
atAttr[1].type = CKA_ID;
atAttr[1].pValue = pIDValue;    // <-- pass here new ID value pointer
atAttr[1].ulValueLen = ulIDLen; // <-- pass here new ID length
rv = g_pFunctionList->C_SetAttributeValue(hSession, pkcs11_hPubKey, atAttr, 2);
rv = g_pFunctionList->C_SetAttributeValue(hSession, pkcs11_hPrvKey, atAttr, 2);

最新更新