1

我编写了一些代码,在令牌中写入公钥和私钥的密钥对。从密钥对中,我创建 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 完全相同?任何人都可以帮忙吗?

4

1 回答 1

0

如果您的 cryptoki 库允许,您可以通过调用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);

于 2020-07-21T10:20:27.087 回答