Sign json parameters with digital certificate C #

1

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

Exception: The provider was unable to 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);
        }
    
asked by anonymous 07.07.2017 / 12:54

0 answers