Decrypt and verify PKCS7 message in C#

Rocky Mishra 1 Reputation point
2021-12-05T07:53:54.657+00:00

I am trying to decrypt and verify PKCS7 response I am getting from client using C#. Initially I tried Enveloping and signing my payload and followed the answer mentioned here.

Now I am getting response in PKCS7 again and having trouble in Decrypting and verifying the response.

I tried using EnvelopedCMS:
ecms.Decode(Convert.FromBase64String(payloadContent));

ecms.Decrypt(new X509.X509Certificate2Collection { _signerCert });

string decodedContent = Encoding.UTF8.GetString(ecms.ContentInfo.Content);

Here _signerCert is my own certificate with private key.
I could see my required response in the decodedContent along with some of the client's information and some unknown ASCII characters.

I also tried using BouncyCastle's CmsEnvelopedCMS but couldn't process further.

Does anyone know how can I achieve decryption and verification of incoming response?
I also have posted the same question here.

Developer technologies | C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.