How to create a self-signed certificate for development suitable to sign MimeKit Messages?
MimeKit has its own CmsSigner. When i try to load the certificate into MimeKit CmsSigner:
X509Certificate2 cert = new X509Certificate2(@"cert.pfx", "xpto", X509KeyStorageFlags.Exportable);
var signer = new MimeKit.Cryptography.CmsSigner(cert);
it throws:
'The certificate cannot be used for signing.'
The problem is that the default algorithm used by CmsSign has to be the same algorithm used to create the certificate key, in my case, SHA1.
Here how was loaded for an S/MIME certificate:
X509Certificate2 cert = new X509Certificate2(@"ca.p12", "xpto", X509KeyStorageFlags.Exportable);
var signer = new CmsSigner(cert);
signer.DigestAlgorithm = DigestAlgorithm.Sha1;
MultipartSigned.Create( signer, mimeMessage.Body);