Sign json parameters with digital certificate C#

Asked

Viewed 668 times

1

I’m trying to integrate with a webservice, which requires the message to be encrypted to PKS7 standard, but when I try to digitally sign the message, I’m getting this error:

Exception: The provider could not perform the action because the context was acquired as silent.

public static byte[] SignFile(X509Certificate2Collection certs, byte[] data)
    {
        try
        {
            ContentInfo content = new ContentInfo(data);
            SignedCms signedCms = new SignedCms(content, false);
            if (VerifySign(data))
            {
                signedCms.Decode(data);
            }
            foreach (X509Certificate2 cert in certs)
            {
                CmsSigner signer = new CmsSigner(cert);
                signer.IncludeOption = X509IncludeOption.WholeChain;
                signedCms.ComputeSignature(signer);
            }
            return signedCms.Encode();
        }
        catch (Exception ex)
        {
            throw new Exception("Erro ao assinar arquivo. A mensagem retornada foi: " + ex.Message);
        }
  • 1

    Try to call signedCms.ComputeSignature(signer, false) - SOEN

  • Thanks, it worked, that’s right!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.