need some help with a .net 2 secure email script that i've got. i get this message
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
here is the code i'm running.
please help
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
here is the code i'm running.
Code:
private void SendSecureEmailTest(string senderEmail, string senderName, string recipientEmail, string recipientName, string subject, string body, string host)
{
//get cert
X509Certificate2 cert = new X509Certificate2("D:\\hshome\\munch\\tigerfish.com.au\\ssl\\tigerderx509.cer");
CmsRecipient cmsRecipient = new CmsRecipient(SubjectIdentifierType.IssuerAndSerialNumber, cert);
//get bytes
UTF8Encoding encoding = new UTF8Encoding();
byte[] msgBytes = encoding.GetBytes(body);
//encrpyte
ContentInfo contentInfo = new ContentInfo(msgBytes);
EnvelopedCms envelopedCms = new EnvelopedCms(contentInfo);
envelopedCms.Encrypt(cmsRecipient);
byte[] encodedMsgBytes = envelopedCms.Encode();
//send
using (MemoryStream contentStream = new MemoryStream(encodedMsgBytes))
{
AlternateView encryptedBody = new AlternateView(contentStream, "application/x-pkcs7-mime;smime-type=enveloped-data;name=smime.p7m;");
encryptedBody.TransferEncoding = TransferEncoding.Base64;
using (MailMessage message = new MailMessage(new MailAddress(senderEmail, senderName, Encoding.UTF8), new MailAddress(recipientEmail, recipientName, Encoding.UTF8)))
{
message.Subject = subject;
message.BodyEncoding = Encoding.UTF8;
message.SubjectEncoding = Encoding.UTF8;
message.AlternateViews.Add(encryptedBody);
message.Headers.Add("content-disposition", "attachment;filename=\"smime.p7m\"");
SmtpClient client = new SmtpClient(host);
client.Send(message);
}
}
}
please help