开发者

"An internal certificate chaining error has occurred" error while signing email in C#

开发者 https://www.devze.com 2023-02-06 10:55 出处:网络
I\'m trying to digitally sign some content, including the whole certificate chain in the signature (so that recipient can verify the signature with no problems).I get the following error: \"An interna

I'm trying to digitally sign some content, including the whole certificate chain in the signature (so that recipient can verify the signature with no problems). I get the following error: "An internal certificate chaining error has occurred" when calling the ComputeSignature() method.

Both root CA and intermediate CA certificates are installed in my machine. I'm trying to sign the content with a Verisign email certificate.

Intermediate CA certificate is: VeriSign Class 1 Individual Subscriber CA - G3

Root CA certificate is: VeriSign Class 1 Public Primary Certification Authority - G3

Here's the code I'm using:

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

    SignedCms signedCms开发者_StackOverflow = new SignedCms(new ContentInfo(messageBytes), true);

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

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

    signedCms.ComputeSignature(cmsSigner, false); 

    return signedCms.Encode();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号