签名和电子邮件 - 找不到原始签名者

时间:2012-05-23 12:58:19

标签: .net x509certificate

我有以下代码但是当我运行代码时收到错误 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();
    }

1 个答案:

答案 0 :(得分:0)

您是否尝试删除此行:

cmsSigner.IncludeOption = X509IncludeOption.WholeChain;

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