【问题标题】:PKCS#11 C_WrapKey returns CKR_GENERAL_ERRORPKCS#11 C_WrapKey 返回 CKR_GENERAL_ERROR
【发布时间】:2018-10-16 09:19:47
【问题描述】:

我已经效仿了:https://pkcs11interop.net/doc/_high_level_a_p_i_2_24__wrap_and_unwrap_key_test_8cs-example.html

使用 rsa 密钥来包装对称密钥,并且成功了。

我想要实现的是包装一个非对称密钥(rsa 私钥)。我所做的只是用私钥的 ObjectHandle 替换“secretKey”变量。但是,每次调用 Wrapkey 函数时都会收到 CKR_GENERAL_ERROR。

有人可以解释为什么这不起作用吗?我在规范中找不到任何阻止包装非对称密钥的内容。

生成的私钥具有以下属性:

List<ObjectAttribute> privateKeyAttributes = new List<ObjectAttribute>();
privateKeyAttributes.Add(new ObjectAttribute(CKA.CKA_TOKEN, true));
privateKeyAttributes.Add(new ObjectAttribute(CKA.CKA_PRIVATE, true));
privateKeyAttributes.Add(new ObjectAttribute(CKA.CKA_ID, ConvertUtils.HexStringToBytes(id)));
privateKeyAttributes.Add(new ObjectAttribute(CKA.CKA_SENSITIVE, false));
privateKeyAttributes.Add(new ObjectAttribute(CKA.CKA_DECRYPT, true));
privateKeyAttributes.Add(new ObjectAttribute(CKA.CKA_SIGN, true));
privateKeyAttributes.Add(new ObjectAttribute(CKA.CKA_SIGN_RECOVER, true));
privateKeyAttributes.Add(new ObjectAttribute(CKA.CKA_EXTRACTABLE, true));

最好的问候,

【问题讨论】:

    标签: c# token pkcs#11


    【解决方案1】:

    您似乎正在尝试使用 CKM_RSA_PKCS 机制来包装 RSA 私钥。 PKCS#11 v2.20 specification 的第 12.1.6 章声明:

    PKCS#1 v1.5 RSA 机制,表示为CKM_RSA_PKCS,是一种 基于 RSA 公钥密码系统的多用途机制和 最初在 PKCS#1 v1.5 中定义的块格式。

    ...

    这种机制可以包装和解包任何适当的密钥 长度。当然,特定的令牌可能无法打包/解包 它支持的每个适当长度的密钥。对于包装, 加密操作的“输入”是CKA_VALUE 的值 被包装的键的属性;类似的展开。

    PKCS#11 规范仅对对称密钥使用术语秘密密钥。此外,CKA_VALUE 属性对于 RSA 私钥无效。这行不通。

    您最好的办法是整理您的设备/库的文档并选择适合您需要的不同包装机制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多