0

我有以下代码,但是当我运行代码时收到错误System.Security.Cryptography.CryptographicException:找不到原始签名者。,为什么会出现这种情况?是因为我的证书设置不正确吗?

    public byte[] GetSignature(string message, X509Certificate2 signingCertificate,
                               X509Certificate2 encryptionCertificate)
    {
        byte[] messageBytes = Encoding.ASCII.GetBytes(message);

        SignedCms signedCms = new SignedCms(new ContentInfo(messageBytes), true);

        CmsSigner cmsSigner = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, signingCertificate);
        cmsSigner.IncludeOption = X509IncludeOption.WholeChain;

        if (encryptionCertificate != null)
        {
            cmsSigner.Certificates.Add(encryptionCertificate);
        }

        Pkcs9SigningTime signingTime = new Pkcs9SigningTime();
        cmsSigner.SignedAttributes.Add(signingTime);

        signedCms.ComputeSignature(cmsSigner, false);

        return signedCms.Encode();
    }
4

1 回答 1

0

您是否尝试过删除此行:

cmsSigner.IncludeOption = X509IncludeOption.WholeChain;

我遇到了与您描述的相同的问题,我也使用了该WholeChain选项,省略它为我解决了问题。我希望它会帮助其他人,即使这个问题是 8 个月前发布的。

于 2012-11-13T06:51:18.830 回答