2010-12-03 70 views
0
public byte[] DoEncrypt(string message, X509Certificate2 cryptCert) 
    { 
     byte[] signedBytes = new System.Text.UTF8Encoding().GetBytes(message); 
     EnvelopedCms encryptedMessage = new EnvelopedCms(new ContentInfo(signedBytes)); 

     CmsRecipientCollection recipients = new CmsRecipientCollection(); 

      CmsRecipient recipient = new CmsRecipient(cryptCert); 
      recipients.Add(recipient); 


     encryptedMessage.Encrypt(recipient); 

     return encryptedMessage.Encode(); 
    } 

当我的应用程序试图对它进行加密抛出异常“encryptedMessage.RecipientInfos”扔类型的异常的消息“System.Security.Cryptography.CryptographicException '与文本“无效的加密消息类型”出现在行“encryptedMessage.Encrypt(收件人)”ASP.Net:“无效的加密消息类型”错误加密消息时

回答

0

如果您实际上正在加密签名数据(如变量名称所示),则不应使用默认内容类型您的ContentInfo。相反,您应该使用允许您指定signedData内容类型的alternative constructor

+0

非常感谢Rasmus,但它没有工作 – 2010-12-03 21:53:53