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.
Does anyone know how can I achieve decryption and verification of incoming response?
Solution found:
I used SignedCms like this as suggested by @bartonjs
SignedCms signedCMS = new SignedCms();
signedCMS.Decode(ecms.ContentInfo.Content);