@Matt East For the error message about 'System.Security.Cryptography.CryptographicException: ASN1 unexpected end of data', it indicates that the decode message was corrupt. You should add the logs to monitor the raw message and the message trying to decode, and investigate why it was modified.
Here is a quick test to repro this issue:
internal class TestSignedCms
{
string oringalMessage="Hello World!";
byte[] encodedMessage;
byte[] encodedMessage2;
SignedCms signedCms;
public TestSignedCms()
{
var cert = new X509Certificate2(@"C:\testCert.pfx", "password");
var cmsSigner = new CmsSigner(cert);
var msg = UTF8Encoding.Unicode.GetBytes(oringalMessage);
var contentInfo = new ContentInfo(msg);
signedCms = new SignedCms(contentInfo);
signedCms.ComputeSignature(cmsSigner);
encodedMessage=signedCms.Encode();
encodedMessage2 = new byte[encodedMessage.Length];
encodedMessage.CopyTo(encodedMessage2,0);
Array.Resize(ref encodedMessage2,encodedMessage.Length-1);
}
public void Run()
{
// Create a new, nondetached SignedCms message.
SignedCms signedCms = new SignedCms();
// encodedMessage is the encoded message received from
// the sender.
signedCms.Decode(encodedMessage2);
Console.WriteLine(UTF8Encoding.UTF8.GetString( signedCms.ContentInfo.Content));
// Verify the signature without validating the
// certificate.
signedCms.CheckSignature(true);
Console.ReadLine();
}
}