Discuss this help topic in SecureBlackbox Forum
Create enveloping CMS signature
The easiest way to create an enveloping CMS signature (the signature that includes the signed data in its body) with SecureBlackbox is using its TElSignedCMSMessage component. Follow the below step-by-step guidance to create one over your data:
TElSignedCMSMessage cms = new TElSignedCMSMessage();
byte[] data = Encoding.UTF8Encoding.UTF8.GetBytes("One thing I can tell you is we got to be free");
cms.CreateNew(data, 0, data.Length);
int sigIndex = cms.AddSignature(); // for new signatures sigIndex will always be 0, but it is a good practice to do it that way
TElCMSSignature sig = cms.get_Signatures(sigIndex);
sig.SigningTime = DateTime.UtcNow;
TElX509Certificate cert = new TElX509Certificate();
int r = cert.LoadFromFileAuto("cert.pfx", "password");
if (r != 0) {
throw new Exception("Failed to load the signing certificate");
}
sig.Sign(cert, null);
While the above call passes null as the second parameter, you can use it to pass a certificate chain to be included in the signature.
cms.Detached = false;
FileStream f = new FileStream("signature.p7s", FileMode.Create);
try
{
cms.Save(f);
}
finally
{
f.Close();
}
That's it, the enveloping signature is now saved in the 'signature.p7s' file.