代码之家  ›  专栏  ›  技术社区  ›  Roman Prykhodko

无法登录数据。Net Core 2.1-出现异常“无法确定签名者证书的签名算法”

  •  0
  • Roman Prykhodko  · 技术社区  · 6 年前

    不久前Net Core引入了SignedCms,因此数据签名成为可能。然而,这并不像看上去那么清楚。我有sign方法,在中效果很好。净额4.6(见下文)

      private byte[] SignData(byte[] data, X509Certificate2 signCertificate, bool isAttached)
        {
            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("Data to sign is missing", nameof(data));
            }
            if (signCertificate == null)
            {
                throw new ArgumentException("Certificate is missing", nameof(signCertificate));
            }
            var signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, signCertificate);
            var signedCms = new SignedCms(new ContentInfo(data), !isAttached);
            signedCms.ComputeSignature(signer);
            return signedCms.Encode();
        }
    

    当我打电话进来的时候。Net 4.6中出现以下异常:

    {System.Security.Cryptography.CryptographicException: Could not determine signature algorithm for the signer certificate.
    at System.Security.Cryptography.Pkcs.CmsSigner.Sign(ReadOnlyMemory`1  data, String contentTypeOid, Boolean silent, X509Certificate2Collection& chainCerts)
    at System.Security.Cryptography.Pkcs.SignedCms.ComputeSignature(CmsSigner signer, Boolean silent)
    at System.Security.Cryptography.Pkcs.SignedCms.ComputeSignature(CmsSigner signer)
    at BusinessLogic.Managers.CryptographyService.SignData(Byte[] data, X509Certificate2 signCertificate, Boolean isAttached)
    

    我在我的电脑中安装了具有上述算法的CSP。Net 4.6它运行良好。 请给出一些建议。

    1 回复  |  直到 6 年前
        1
  •  1
  •   bartonjs    6 年前

    我的电脑中安装了具有上述算法的CSP

    这表明您的非对称算法不是RSA、RSA-PSS、DSA或ECDSA中的一种。

    这个 .NET Framework implementation of SignedCms 要求Windows CMS库进行签名,这些库具有CAPI/CNG扩展点。

    这个 .NET Core implementation of SignedCms 使用。NET加密类并执行CMS格式化,而不要求操作系统执行该工作。它当前没有扩展性模型。

    如果您只对Windows感兴趣,那么可以尝试直接在Windows CMS API中调用P/Invoking。否则,您需要向发出功能请求。净核心( https://github.com/dotnet/corefx/issues ).