SignedCms, sign an existing hash?

Viewed 82

We have got an existing hash and want to create a CMS-formatted signature with the .NET SignedCms class for it.

What kind of content type do we have to pass to the SignedCms ctor?

var contentType = new Oid(""); // What kind of content type to use?
var content = Convert.FromBase64String(hash); // Can either be a SHA1 or a SHA256 hash
var contentInfo = new ContentInfo(contentType, content);
var signedCms = new SignedCms(contentInfo, detached: true); // Do I have to use detached=true?

var signer = new CmsSigner(certificate);
signedCms.ComputeSignature(signer);

var signature = signedCms.Encode();
0 Answers
Related