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”行中。加密(受体)“
答案 0 :(得分:0)
如果您实际上正在加密签名数据(如变量名称所示),则不应使用ContentInfo的默认内容类型。相反,您应该使用允许您指定signedData内容类型的alternative constructor。