views:

93

answers:

0

I'm retrieving a X509Certificate2 from my local X509Store and I'd like to use it to digitally sign emails. I'm using the SignedCms.ComputeSignature to generate the signature, but without the private key it throws exception "Keyset does not exist". So how do I enter the private key programmatically? The ComputeSignature(cmsSigner, false) method will prompt the user when using a winform app, but I'm using a web app. I'm guessing it has something to do with AsymmetricAlgorithm PrivateKey property, but I'm having difficulty finding info on this. Thanks

SignedCms signedCms = new SignedCms(new ContentInfo(messageBytes), true);

CmsSigner cmsSigner = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, signingCertificate);
cmsSigner.IncludeOption = X509IncludeOption.WholeChain;

signedCms.ComputeSignature(cmsSigner, true);