Cryptographic Exception while loading Rebex.Mail.MailMessage from Stream

0 votes
asked May 11, 2012 by velin_achev (280 points)
edited May 14, 2012

Hello,

I have a MailMessage that have been persisted to database using Rebex.Mail.MailMessage.Save(Stream output, MailFormat format) method. The important thing is that the message was SIGNED with user certificate. However, a get a Cryptographic exception while loading back the message using Rebex.Mail.MailMessage.Load(Stream input) method. The message is "Invalid ASN.1 data.".

I'd like to know whether the problem can be in saving the message to the database and should I perform some other operations over that message before calling Save(..) method? The user's certificate is valid.

Regards, Velin Achev

Applies to: Rebex Secure Mail

2 Answers

0 votes
answered May 11, 2012 by Tomas Knopp (58,890 points)
edited May 14, 2012

Hello, we have to have a closer look into the actual MailMessage so that we could help you with this issue. Please use the MimeOption.DoNotParseMimeTree when loading the MailMessage from the database and then save the loaded mail into a file like that:

                   MailMessage message = new MailMessage();
                   message.Options = MimeOptions.DoNotParseMimeTree;
                   message.Load(inputStream);
                   message.Save("mail.eml", MailFormat.Mime);

Then please zip the file and mail it to support@rebex.net for analysis. We should be able to help you.

commented May 11, 2012 by velin_achev (280 points)
edited May 14, 2012

Hi Tomáš,

Thank you for the quick response. Let me use your assistance later, because it appeared that exception mentioned above appeared when the mail was encrypted with the certificate(public key) of one user. So I'd like to inspect that certificate first, then I'll proceed to your services.

Regards, Velin Achev

0 votes
answered May 14, 2012 by velin_achev (280 points)
edited May 14, 2012

The problem was in our code - we used incorrectly the stream, given from Save(Stream output) method of Rebex.Mail.MailMessage class. So we saved that invalid stream to the database and the problem occurred later.

Velin

commented May 14, 2012 by Tomas Knopp (58,890 points)
edited May 14, 2012

Hi Velin, thank you for responding and we are glad that you solved the problem!

...