I am working on a larger application which receives email by POP3, IMAP or through import from .msg Files (Exported form Outlook or dragged over from Outlook).
Recently I received an email with an attachment "smime.p7m". After further inspection it turned out to be a MIME Message with
Content-Type: multipart/signed; protocol="application/x-pkcs7-signature";
Among other parts it contains one section
Content-Type: application/x-pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s"
I tried to verify this signature using OpenPop
as a MIME Message Parser and SignedCms
to check the signature. My attempt looks like this:
var datapart = OpenPop.MessagePart[...];
var part3 = OpenPop.MessagePart[3]; // the signature
var ci = new ContentInfo(datapart);
var sCMS = new SignedCms(ci, detached: true);
sCMS.Decode(part3.Body);
sCMS.CheckHash();
sCMS.CheckSignature(verifySignatureOnly:true);
But no matter what I use for datapart
I always get
System.Security.Cryptography.CryptographicException The hash value is not correct.
How can I verify the signature?
Are there better approaches?