login about faq

Hi, We are evaluating Chilkat .NET component to purchase the license. I am trying to create s/mime encrypted message using this example. It looks like "encrypted.txt" file doesn't get encrytped. Could you please let me know if I am doing something wrong? Thank you.

        Chilkat.Mime mime = new Chilkat.Mime();
        bool success;
        //Any string passed to UnlockComponent begins the 30-day trial
        //mime.UnlockComponent("30-day trial");
        success = mime.UnlockComponent("Anything for 30-day trial");
        if (success == false)
       // success = mime.NewMultipartMixed();
        mime.SetBodyFromXml("This is a message containing a XML file.");
        //  Now insert some files:
        if (success == false)
        Chilkat.CreateCS ccs = new Chilkat.CreateCS();
        Chilkat.CertStore certStore = ccs.OpenCurrentUserStore();
        Chilkat.Cert cert = certStore.FindCertForEmail("matt@chilkatsoft.com");

        // Use the certificate for encryption.
        // This creates an x-pkcs7-mime enveloped message.
        Chilkat.Mime part2 = null;
        part2 = mime.GetPart(1);
        byte[] binaryData = null;
        binaryData = part2.GetBodyBinary();

asked Dec 06 '12 at 11:24

nav100's gravatar image


There are many things wrong with the code fragment.

  1. First, make sure you understand some basic things about MIME: A MIME message is basically a number of header fields, one per line, followed by a double CRLF, followed by the MIME body. The SetBodyFromXml method is setting the body part of the MIME object (i.e. what comes after the double CRLF after the headers). Also, as the name of the function implies, you should be passing an XML string to it -- but you're not. So that doesn't make sense.
  2. There are many Chilkat methods calls in your code snippet that return a success/failure status. You need to check the return value of each method that could fail. If your code misses a failed returns status and blindly continues onward, you can't expect anything good -- and you'll be wondering what went wrong. Check the error where it FIRST occurs, then look at the LastErrorText property on the object instance w/ the failed method call.

answered Dec 06 '12 at 14:56

chilkat's gravatar image

chilkat ♦♦

The code is failing at mime.Encrypt(cert). I looked at LastErrorText property. It doesn't say anything about error detail. Could you please let me know if there are any examples using multipart with encryption? Thanks for your help.

(Dec 07 '12 at 09:24) nav100

The LastErrorText should have lots of information. If not, you're probably looking at the LastErrorText for some other object instance (i.e. not the object instance that made the call to mime.Encrypt)

(Dec 07 '12 at 10:52) chilkat ♦♦

Here is the error message: CertStoreLocation: (registry) HKEY_CURRENT_USER/[Current User Certificate Store] emailAddr: matt@chilkatsoft.com Failed.

(Dec 07 '12 at 13:45) nav100

I created a certificate using makecert.exe. It works now. Thanks

(Dec 07 '12 at 14:49) nav100
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Dec 06 '12 at 11:24

Seen: 1,758 times

Last updated: Dec 07 '12 at 14:49

powered by OSQA