I can use SignedCms or EnvelopedCms classes to verify signatures and decrypt S/MIME data but I need to know in advance if it’s signed or encrypted. If it’s signed and I use EnvelopedCms, I get an exception. If it’s encrypted and I use SignedCms – again, exception.
I don’t see any way with .NET own APIs to determine if the data is signed or encrypted. So I want to peek into this data, maybe there is a flag which can be detected? I don’t need/want a full-fledged pcks7 parser like BounceCastle (it would be too heavy dependency for my library).
Because the format is binary, it’s not easy to find out what exactly I should be looking for. RFC spec for pcks7 is quite complex and does not give an obvious answer. Or maybe there is a lightweight C# pcks7 parsing source code around which would let me solve this task?