Advertisement
Guest User

Untitled

a guest
Dec 1st, 2010
1,437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. SignedCms Cms = new SignedCms(new ContentInfo(messageData));
  2.             CmsSigner Signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, new X509Certificate2(@"c:\serv.pfx", "123"));
  3.             Cms.ComputeSignature(Signer);
  4.             byte[] SignedBytes = Cms.Encode();
  5.  
  6.             ContentInfo content = new ContentInfo(SignedBytes);
  7.             EnvelopedCms envelopedCms = new EnvelopedCms(content);
  8.             CmsRecipient recipient = new CmsRecipient(SubjectIdentifierType.SubjectKeyIdentifier, this.certificate);
  9.             envelopedCms.Encrypt(recipient);
  10.             byte[] encryptedBytes = envelopedCms.Encode();
  11.  
  12.             message.To.Add(new MailAddress(provMail));
  13.  
  14.             MemoryStream encryptedStream = new MemoryStream(encryptedBytes);
  15.             AlternateView encryptedView = new AlternateView(encryptedStream, "application/pkcs7-mime; smime-type=enveloped-data");
  16.             message.AlternateViews.Add(encryptedView);
  17.  
  18.             getSmtpConnection().Send(message);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement