【问题标题】:PKCS#11Interop.X509Store unable to find Private KeyPKCS#11Interop.X509Store 找不到私钥
【发布时间】:2021-11-17 11:33:48
【问题描述】:

Pkcs11X509Certificate 无法在某些令牌中找到私钥。

Pkcs11X509Certificate.GetRSAPrivateKey() 产生空值。然后,当我运行 SignedXml.ComputeSignature() 时,我收到以下错误:

System.Security.Cryptography.CryptographicException: '未加载签名密钥。'

【问题讨论】:

标签: pkcs#11 pkcs11interop


【解决方案1】:

将以下代码(概念证明)添加到 Pkcs11X509Certificate.FindKey 可以正常工作。 基本上我从搜索模板属性中删除了 CKA.CKA_LABEL 并找到了证书私钥。

// Contrary to what PKCS#11 specification suggests, subject of the private key is not readable even after login.
// So if we cannot find private key with subject, we will search for private keys without subject. 
if (keyHandle == null)
{
    searchTemplate = new List<IObjectAttribute>()
    {
        session.Factories.ObjectAttributeFactory.Create(CKA.CKA_CLASS, keyClass),
        session.Factories.ObjectAttributeFactory.Create(CKA.CKA_TOKEN, true),
        session.Factories.ObjectAttributeFactory.Create(CKA.CKA_ID, ckaId),
        //session.Factories.ObjectAttributeFactory.Create(CKA.CKA_LABEL, ckaLabel),
    };

    foreach (IObjectHandle foundObjectHandle in session.FindAllObjects(searchTemplate))
    {
        keyHandle = foundObjectHandle;
        break;
    }
}

【讨论】:

  • 我想知道这是否可以添加到 GitHub 的 Pkcs11Interop.X509Store 项目中。
  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 1970-01-01
  • 2018-08-04
  • 1970-01-01
  • 2012-09-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多