encryption - ASP.Net: "Invalid cryptographic message type" error when encrypting message -
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(); } when application tries encrypt message throws exception 'encryptedmessage.recipientinfos' threw exception of type 'system.security.cryptography.cryptographicexception' text "invalid cryptographic message type" occurs in line "encryptedmessage.encrypt(recipient)"
if encrypting signed data (as variable names suggests), should not use default content type contentinfo. instead should use alternative constructor allows specify signeddata content type.
Comments
Post a Comment