-
-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot decrypt without adding certificate to personal store #38
Comments
This is the same issue reported in http://stackoverflow.com/questions/22324124/mimekit-causing-bad-data-when-decrypting-an-email however it is probably also good to have it here :) When I try to build your project myself, then the bouncy castle project cannot load in visual studio 2012. |
Are you using the visual-studio-2010 branch of bc-csharp? The default (master) branch is in vs2003 format. I've updated my stackoverflow answer with the correct way to import the certificate + the private key (your implementations above are only importing the certificate and not the private key). For convenience, I'll post the proper way to import the certificate + private key here as well: private SecureMimeContext CreateSecureMimeContext (string certificateFilename, string certificatePassword)
{
var secureMimeContext = new WindowsSecureMimeContext ();
using (var stream = File.OpenRead (certificateFilename))
secureMimeContext.Import (stream, certificatePassword);
return secureMimeContext;
} It's a common confusion for many people, but X509Certificate2 does not include a private key, it only references a private key, so if you use certificate.RawData or certificate.GetRawData() and parse the result, you lose the reference to the private key, which is why your implementations did not work. I'll add an in-memory-only SecureMimeContext to MimeKit for the next release, but I'm curious why you do not want to import the certificates/keys into the user's certificate store? (I'm not saying that you are wrong to not want to do that, I'm just curious so I can better understand use-cases that I did not originally plan for). |
…eys/crls Adds a feature requested in issue #38
Hi. Even though I import it like you show above, I still get the same exception:
Was this because there was an error in CreateSecureMimeContext? I will explain my scenario of use later on :) |
What happens if you use the DummySecureMimeContext instead of the WindowsSecureMimeContext? |
Wohoo! The DummySecureMimeContext works! Thought I had checked that.. Thank you very much for all your help jstedfast. I will mark your answer as correct on SO as well. The reason why I would like to keep certificates in memory:
4.3: Sometimes I got this exception instead:
5: Attempt to decrypt mail requiring cert1.pfx using DefaultSecureMimeContext
I have checked my certmgr.msc - personal store, and both certificates are there. I also switch servers a lot, and it is easier to simply keep them in a file |
Cool, glad that the DummySecureMimeContext works for you. I've added DummySecureMimeContext to the main MimeKit module and renamed it to TemporarySecureMimeContext (hopefully this is a better name, I didn't like Dummy). Thanks for explaining about the errors you get when you have multiple certificates with the same root. I never would have guessed that problem. I've just released a MimeKit 0.28 nuget package which contains the TemorarySecureMimeContext. |
Hi.
When I attempt to decrypt an email using the WindowsSecureMimeContext it throws the exception:
Which basically means, that it cannot find the certificate to use.
However I have imported the certificate:
And a different way of importing:
However none of them works.
I have tried to decrypt myself, which works great.
I load the certificate like this:
So I believe it is an issue, that it is so dependent on the certificate store.
Can you provide a fix or an idea on how to circumvent this issue?
The text was updated successfully, but these errors were encountered: