Decrypt method throws System.FormatException

0 votes
asked Sep 16, 2010 by M. Inam (140 points)
edited Sep 17, 2010

Hello,

This is a licensed version of Secure Mail component. I'm using the same code indicated in S/MIME Tutorial page as follows:

` private void buttonLoadEml_Click(object sender, EventArgs e) { try { string emlFileName = GetEmlFilePath(); if (string.IsNullOrEmpty(emlFileName)) { return; } MailMessage message = new MailMessage(); message.Load(emlFileName);

            // decrypt the message if it is encrypted 
            if (message.IsEncrypted)
            {
                if (!message.CanDecrypt)
                    throw new ApplicationException
                    (
                      "Message cannot be decrypted. You do not have the private key."
                    );

                message.Decrypt();
            }

            this.textBox1.Text = message.BodyText;
        }
        catch (Exception ex)
        {
            this.textBox1.Text = ex.ToString();
        }
    }

`

Here are the exception details:

System.FormatException: Input string was not in a correct format. at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) at System.String.Format(IFormatProvider provider, String format, Object[] args) at AzIwhU.bjJTWY.bbBzTnZ(Byte[] ) at Rebex.Security.Cryptography.Pkcs.EnvelopedData.Decrypt() at Rebex.Mime.MimeEntity.Decrypt() at Rebex.Mail.MailMessage.Decrypt() at CertificateEnumerator.MainForm.buttonLoadEml_Click(Object sender, EventArgs e) in C:\Users\inm\Documents\Visual Studio 2008\Projects\CertificateEnumerator\CertificateEnumerator\MainForm.cs:line 173

Applies to: Rebex Secure Mail

1 Answer

+1 vote
answered Sep 17, 2010 by Vit Zyka (1,000 points)
edited Sep 17, 2010

Hello,

it seems us that you encountered the known bug of the Rebex Secure Mail. We fixed it in 2010-07-20 (version 1.0.3854.0).

Most probably you should obtain a CryptographicException with error message "Unsupported encryption algorithm" due to missing AES cryptography support. AES was added only in recent time so you need the fresh code for it.

We recommend to you to download the latest component version. It should solve the problem. If not, please let us know again.

...