none
The code example "How to: Envelope a Message for One Recipient" throw exception when the certificate "Recipient1" is created by makecert RRS feed

  • Question

  • I compile and execute the example code in http://msdn.microsoft.com/en-us/library/bb924565.aspx with title "How to: Envelope a Message for One Recipient".

    I got exception with message "Key error" when the process execute the statement:
        envelopedCms.Decrypt(envelopedCms.RecipientInfos[0]);
    Can any one tell me what is wrong and how to fix it?

    My Detail steps:
    1. Use following statement to create appropriate public/private key pairs.

    Makecert -n "CN=Recipient1" -ss My

    2. export the public key certificate, and then import it into the AddressBook certificate store by following the procedure in How to: Export and Import a Public Key Certificate.

    3. compile the code in http://msdn.microsoft.com/en-us/library/bb924565.aspx and execute.


    By the way, my OS is Vista and my tool is C# 2008 express.


    In fact, if I replace the Certificate "Recipient1" created by makeceert with the valid certificate of my bank accocunt, every thing is OK.

    Thanks
    Wednesday, July 8, 2009 2:49 AM

Answers

  • The solution is:
    use command 
    makecert -r -pe -sky Exchange -n "CN=Recipient1" -ss MY
    in stead of 
    Makecert -n "CN=Recipient1" -ss My
    • Marked as answer by hjyanghj Wednesday, July 29, 2009 3:23 PM
    Wednesday, July 29, 2009 3:23 PM