{"id":3403,"date":"2012-09-24T16:00:01","date_gmt":"2012-09-24T14:00:01","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=3403"},"modified":"2013-06-26T09:20:21","modified_gmt":"2013-06-26T07:20:21","slug":"send-encrypted-email-smime-aes-256","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/send-encrypted-email-smime-aes-256","title":{"rendered":"Send encrypted email using S\/MIME (AES\u2011256)"},"content":{"rendered":"<p>In many cases it is required to use better that standard encryption algorithms. With Mail.dll it is easy to specify algorithm that is used for encryption. In this article we&#8217;ll show how to <strong>send S\/MIME encrypted and signed email<\/strong> using Mail.dll <a href=\"\\mail\">email component<\/a> and AES-256 and SHA-512.<\/p>\n<p>If you don&#8217;t need to specify encryption algorithm you can lean on default values: <a href=\"\/blog\/send-encrypted-email-using-smime\">send encrypted email using S\/MIME<\/a>.<\/p>\n<p>Encryption algorithm selection is done through <em>Algorithm<\/em> property of the <em>EncryptionConfiguration <\/em> class. You can use <em>CommonOids<\/em> class static properties to retrieve common oids (object identifiers):  <em>TrippleDes<\/em> (3-DES), <em>Aes128<\/em>, <em>Aes256<\/em>.<\/p>\n<h2>Encryption using MailBuilder<\/h2>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nEncryptionConfiguration encryption = new EncryptionConfiguration();\r\nencryption.Algorithm = new Oid(CommonOids.Aes256);\r\nencryption.Certificates.Add(new X509Certificate2(...));\r\nencryption.Certificates.Add(new X509Certificate2(...));\r\n\r\nSignatureConfiguration signature = new SignatureConfiguration(\r\n    new X509Certificate2(...));\r\nsignature.Algorithm = new Oid(CommonOids.Sha512);\r\n\r\nMailBuilder builder = new MailBuilder();\r\nbuilder.Text = &quot;Encrypted and signed&quot;;\r\nbuilder.EncryptWith(encryption);\r\nbuilder.SignWith(signature);\r\n\r\nIMail mail = builder.Create();\r\n<\/pre>\n<h2>Encryption using fluent interface<\/h2>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nEncryptionConfiguration encryption = new EncryptionConfiguration();\r\nencryption.Algorithm = new Oid(CommonOids.Aes256);\r\nencryption.Certificates.Add(new X509Certificate2(...));\r\nencryption.Certificates.Add(new X509Certificate2(...));\r\n\r\nSignatureConfiguration signature = new SignatureConfiguration(\r\n    new X509Certificate2(...));\r\nsignature.Algorithm = new Oid(CommonOids.Sha512);\r\n\r\nIMail mail = Mail.Text(&quot;Encrypted&quot;)\r\n    .EncryptWith(encryption)\r\n    .SignWith(signature)\r\n    .Create();\r\n<\/pre>\n<p>Remember to <strong>encrypt your emails with both sender\u2019s and receiver\u2019s certificates<\/strong>. This way both parties are able to decrypt such emails.<\/p>\n<h2>Sending email using SMTP<\/h2>\n<p>Now we can connect to SMTP server and send the email we recently created:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing (Smtp client = new Smtp())\r\n{\r\n    client.Connect(&quot;smtp.example.com&quot;); \/\/ or ConnectSSL\r\n    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n    client.SendMessage(email);\r\n    client.Close();\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In many cases it is required to use better that standard encryption algorithms. With Mail.dll it is easy to specify algorithm that is used for encryption. In this article we&#8217;ll show how to send S\/MIME encrypted and signed email using Mail.dll email component and AES-256 and SHA-512. If you don&#8217;t need to specify encryption algorithm [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,33,49,50,57],"class_list":["post-3403","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-email-component","tag-smime","tag-smtp","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3403"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=3403"}],"version-history":[{"count":22,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3403\/revisions"}],"predecessor-version":[{"id":4127,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3403\/revisions\/4127"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=3403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=3403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=3403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}