<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rssdatehelper="urn:rssdatehelper"><channel><title>Blog</title><link>http://www.umlaut.be</link><pubDate></pubDate><generator>umbraco</generator><description></description><language>en</language><item><title>Simple GoogleMap made easy</title><link>http://www.umlaut.be/blog/2010/2/23/simple-googlemap-made-easy.aspx</link><pubDate>Tue, 23 Feb 2010 12:57:03 GMT</pubDate><guid>http://www.umlaut.be/blog/2010/2/23/simple-googlemap-made-easy.aspx</guid><content:encoded><![CDATA[ 
<p>I recently had to make a page showing different locations each
with it own little googlemap.</p>

<p>To make it easy to use i used jQuery to hook in a create the
googlemap from the html. The map generatet is a simple map with one
marker and centered on this marker. with an width and height set to
400px</p>

<p><img src="/media/3498/ss.jpg" width="376" height="461" alt="gmaps"/></p>

<p>So I used span tag html to set the settings need for generating
each googlemap.<br />
 I then use jQuery to look for a container that have one or multple
of theese maps inside and add a map to the specific "mapItem"</p>

<p>The html needed for one item is as shown below:</p>

<p>&nbsp;</p>

<pre class="brush:html;">
&lt;div class="Map"&gt;<br />
  &lt;span class="MapSettings"&gt;<br />
    &lt;span class="longtitude"&gt;Na;&lt;/span&gt;<br />
    &lt;span class="longtitude"&gt;Na&lt;/span&gt;<br />
    &lt;span class="mapId"&gt;Map0&lt;/span&gt;<br />
    &lt;span class="address"&gt;Pentia store kongensgade 66 copenhagen denmark&lt;/span&gt;<br />
    &lt;/span&gt;<br />
    &lt;div id="Map0" class="GoogleMap" style="width:400px; height:400px;"&gt;<br />
    &lt;/div&gt;<br />
  &lt;/div&gt;<br />
</pre>

<p>&nbsp;</p>

<p>To get it all to wok you of course need a googlemapApi key get
from <a
href="http://code.google.com/intl/da-DK/apis/maps/signup.html"
target="_blank">here</a></p>

<p>Here is the jquery file i used to hook in on document ready
function note if the longtitude and/or latitude isn't set i'l try
to and a marker to map from the address if that fails to you'll get
an invalide map.</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<pre class="brush:javascript">
jQuery(document).ready(function()
{
  buildMapsFromHTML();
}
)

/*****************

*  MAP SEETINGS  *

*****************/
var map;
var geocoder;
var zoomLevel = 14;
var mapIndex = 0;
 

/*****************

*  MAP FUNCTIONS *

*****************/
function buildMapsFromHTML(){
  var googleMaps = jQuery(".Map");
  var i;
  for (i = 0; i &lt; googleMaps.length; i++)
  {
    mapIndex = i;
    addMap(googleMaps[i],mapIndex);
  }
}

function addMap(mapSettings) {
  // GET SETTINGS FROM HTML
  var setting = jQuery(mapSettings).children(".MapSettings");
  var mapId = jQuery(setting).children(".mapId").html();
  var longtitude = jQuery(setting).children(".longtitude").html();
  var latitude = jQuery(setting).children(".latitude").html();
  var address = jQuery(setting).children(".address").html();

 
  if (latitude != "Na" || longtitude != "Na") {
    initializeMap(mapId);
    addMarkerToMap(longtitude, latitude);
    centerMap(longtitude, latitude);
  }
  else{
    generateMapFromAddress(address,mapId);
  }
}

function initializeMap(mapId) {
   map = new GMap2(document.getElementById(mapId));
}

function generateMapFromAddress(address,mapId) {
  var coordinate = cordinatesFromGoogle(address,mapId)
}

function cordinatesFromGoogle(address,mapId) {

  geocoder = new GClientGeocoder();

  geocoder.getLatLng(address, function(point) { 
  if(point) {
    var longtitude = point.lng().toFixed(5)
    var latitude = point.lat().toFixed(5)
    initializeMap(mapId);
    addMarkerToMap(longtitude, latitude);
    centerMap(longtitude, latitude);
  }
  })
}

function addMarkerToMap(longtitude, latitude) {
  var point = new GLatLng(latitude, longtitude);
  var marker = new GMarker(point);
  map.addOverlay(marker);
}

function centerMap(longtitude, latitude) {
   var point = new GLatLng(latitude, longtitude);
    map.setCenter(point, zoomLevel);
}
</pre>

<p>&nbsp;</p>

<p>So an example html to bind it all together could look like
this:</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<pre class="brush:html;">
&lt;html&gt;
&lt;head&gt;
&lt;script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;key=localhost type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="googlMaps.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div class="Map"&gt;
  &lt;span class="MapSettings"&gt;
    &lt;span class="longtitude"&gt;Na&lt;/span&gt;
    &lt;span class="latitude"&gt;Na&lt;/span&gt; 
    &lt;span class="mapId"&gt;Map0&lt;/span&gt; 
    &lt;span class="address"&gt;store kongensgade 66 copenhagen denmark&lt;/span&gt; 
  &lt;/span&gt;
    &lt;div id="Map0" class="GoogleMap" style="width:400px; height:400px;"&gt;
    &lt;/div&gt;
 &lt;/div&gt;
 
 &lt;div class="Map"&gt;
  &lt;span class="MapSettings"&gt;
    &lt;span class="longtitude"&gt;Na&lt;/span&gt;
    &lt;span class="latitude"&gt;Na&lt;/span&gt; 
    &lt;span class="mapId"&gt;Map1&lt;/span&gt; 
    &lt;span class="address"&gt;store kongensgade 66 copenhagen denmark&lt;/span&gt; 
  &lt;/span&gt;
    &lt;div id="Map1" class="GoogleMap" style="width:400px; height:400px;"&gt;
    &lt;/div&gt;
 &lt;/div&gt;
 
 &lt;/body&gt;
&lt;/html&gt;


</pre>

<p>If no longtitude or/and latitude is set i gets the marker from
the address.<br />
 and Na should be used to say that you dont have those values.
Offcourse it could be extended to specify which kind of map and so
on. This could be set in the settings as well togehter with
zoomlevel and so on.</p>

<p>remember to set the googlemap key to your domain</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>
]]></content:encoded></item><item><title>Adding captcha "Recaptcha Umbraco Blog"</title><link>http://www.umlaut.be/blog/2010/1/22/adding-captcha-recaptcha-umbraco-blog.aspx</link><pubDate>Fri, 22 Jan 2010 10:26:03 GMT</pubDate><guid>http://www.umlaut.be/blog/2010/1/22/adding-captcha-recaptcha-umbraco-blog.aspx</guid><content:encoded><![CDATA[ 
<p>So after i my self got spammed by a lot of robots on my blog i
browsed the internet to find an easy way to add captcha for the
comment part of my blog.</p>

<p>So i found the easiest way to do was using recaptcha, which can
be found here <a href="http://recaptcha.net"
target="_blank">recaptcha.net</a>. So before we start head over
there and create an account.</p>

<p>Step 1:</p>

<p>Create recaptcha.net account&nbsp; <a
href="http://recaptcha.net" target="_blank">recaptcha.net</a></p>

<p>&nbsp;</p>

<p>Step 2:</p>

<p>Download the .Net package containing the recaptcha.dll</p>

<p>&nbsp;</p>

<p>Step 3:</p>

<p>Download from you site frmBlogComment.ascx placed in
siteroot/usercontrols</p>

<p>&nbsp;</p>

<p>Step4:</p>

<p>Edit frmBlogComment.ascx</p>

<p>add the following lines</p>

<p>&nbsp;</p>

<pre class="brush: c#">
&lt;%@ Import Namespace="Recaptcha"&gt;
&lt;%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha"&gt;

void btnSubmit_Click1(object sender, EventArgs args)
{
  if (recaptcha.IsValid)
  {
     btnSubmit_Click(sender,args);
  }
}

</pre>

<p>These lines should be right after the "control tag" "&lt;%@
Control ...... %&gt;"</p>

<p>&nbsp;</p>

<p>Futher down you can now add the recaptcha usercontrol</p>

<p>&lt;recaptcha:RecaptchaControl<br />
 ID="recaptcha"<br />
 runat="server"<br />
 PublicKey=...<br />
 PrivateKey=....<br />
 /&gt;</p>

<p>&nbsp;</p>

<p>ofcourse with your privatekey and publickey..</p>

<p>&nbsp;</p>

<p>Step 5:</p>

<p>Upload recaptcha.dll to your webroot/bin</p>

<p>Upload the newly edited&nbsp; frmBlogComment.ascx to you
webroot/usercontrols/</p>

<p>&nbsp;</p>

<p>And you should be all done and no more bots should spam your
blog I hope.</p>

<p>This post is for them that dont want to recompile umbraco, it
would be a much better solution to add an reference to the
recaptcha.dll</p>

<p>&nbsp;</p>
]]></content:encoded></item><item><title>Encrypting and signing  Mail in .Net part 5/5 (Encrypting the content and sending the mail)</title><link>http://www.umlaut.be/blog/2010/1/19/encrypting-and-signing--mail-in-net-part-55-(encrypting-the-content-and-sending-the-mail).aspx</link><pubDate>Tue, 19 Jan 2010 12:40:28 GMT</pubDate><guid>http://www.umlaut.be/blog/2010/1/19/encrypting-and-signing--mail-in-net-part-55-(encrypting-the-content-and-sending-the-mail).aspx</guid><content:encoded><![CDATA[ 
<p style="display:none;">Topic: How to encrypt and sign mail c#.
Signed mail in c#, signing c#, c# send encrypted mail, signed
encrypted mail c#, S/MIME messages,Sending encrypted email - C#</p>

<p>Final part in the serie c# encrypting mail.</p>

<p>&nbsp;</p>

<p>So now we got the content build and signed. Now what is left to
do i encrypting the content.</p>

<p>In this post we have a look at how the structure of the content
should just before it is encrypted, and how to encrypt the
content.</p>

<p><a href="/blog/2010/1/12/encrypting-and-signing-mail-in-net-part-15.aspx"
title="Encrypting and signing Mail in .Net part 1/5">Link to part
1</a>, <a href="/blog/2010/1/13/encrypting-and-signing--mail-in-net-part-25-(retrieving-certificats).aspx"
title="Encrypting and signing Mail in .Net part 2/5 (retrieving certificats)">
part 2</a>, <a href="/blog/2010/1/16/encrypting-and-signing-mail-in-net-part-35-(building-the-content---with-attachments).aspx"
title="Encrypting and signing Mail in .Net part 3/5 (Building the content - with attachments)">
part 3</a>, <a href="/blog/2010/1/18/encrypting--and-signing-mail-in-net-part-45-(signing-the-content).aspx"
title="Encrypting and signing Mail in .Net part 4/5 (Signing the content)">
part 4</a></p>

<p>To encrypt the content I will use the GetCert method that we did
in part 4 of this series.</p>

<p>As with the signing part we will split this encryption into two
bits. adding boundary to the content and encrypting part.</p>

<p>First the encrypting part:</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<pre class="brush: c#">
 public byte[] DoEncrypt(string message, X509Certificate2 encryptionCertificates)
           {
               byte[] messageBytes = Encoding.ASCII.GetBytes(message);

               EnvelopedCms envelopedCms = new EnvelopedCms(new ContentInfo(messageBytes));

               CmsRecipient recipients = new CmsRecipient(SubjectIdentifierType.IssuerAndSerialNumber, encryptionCertificates);

               envelopedCms.Encrypt(recipients); 

               return envelopedCms.Encode();
           }

</pre>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>With this function done we can now ready the content for
encryptions. We add a simple boundary to the content and specifies
what type the innner boundary is of. Important that if you skipped
the signing part that you change this accordingly to match the type
of you content.</p>

<p>Here is the code for encrypting and sending the mail:</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<pre class="brush: c#">
 public void encrypt(string content)
       {
           MailMessage message = new System.Net.Mail.MailMessage();
           string encryptedContentType = "application/x-pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"";
           string signatureBoundry2 = "--PTBoundry=3";
           StringBuilder fullUnencryptedMessageBuilder = new StringBuilder();
           fullUnencryptedMessageBuilder.Append("Content-Type: ");
           fullUnencryptedMessageBuilder.Append("multipart/signed; ");
           fullUnencryptedMessageBuilder.Append(" boundary=\"");
           fullUnencryptedMessageBuilder.Append(signatureBoundry2);
             fullUnencryptedMessageBuilder.Append("\"; protocol=\"application/x-pkcs7-signature\"; micalg=SHA1; ");
           
           fullUnencryptedMessageBuilder.Append("\r\n");
           fullUnencryptedMessageBuilder.Append("Content-Transfer-Encoding: ");
           fullUnencryptedMessageBuilder.Append(TransferEncoding.SevenBit);
           fullUnencryptedMessageBuilder.Append("\r\n\r\n");
           fullUnencryptedMessageBuilder.Append(content); 

           string fullUnencryptedMessage = fullUnencryptedMessageBuilder.ToString();

           byte[] encryptedBytes = DoEncrypt(fullUnencryptedMessage, GetCert());

           MemoryStream stream = new MemoryStream(encryptedBytes);
           AlternateView view = new AlternateView(stream, "application/pkcs7-mime; smime-type=signed-data;name=smime.p7m");
           message.AlternateViews.Add(view);
           message.To.Add("youremail@yourdomain.com");
        
           message.From = new MailAddress("someone@yourdomain.com");
           message.Subject = "TEST";
           SmtpClient smtp = new SmtpClient("smtp.yourdomain.com");
           smtp.Send(message);

       
       }
</pre>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>This function also sends out the mail you might wanna spilt this
up to seperate methods. And do remember to give valide email
adresses and a sane smtphost.</p>

<p>Now lets have a look at the result:</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><img src="/media/2987/mailbui5l_500x129.jpg"  width="500"  height="129" alt="mailbui5l"/></p>

<p>Yes there is a warning with the signature but rember in part 1
where did a selfsigned certificate this is the problem, but you cal
always just accept the signature as trusted in your outlook.</p>

<p>Okay so how doesn't the content that we build look like just
before it is encrypted ?</p>

<p>If hightligthe the different steps we done in this series.</p>

<p>&nbsp;</p>

<p><img src="/media/2994/mailbui34l_535x423.jpg"  width="535"  height="423" alt="mailbui34l"/></p>

<p><a href="/media/2994/mailbui34l.jpg">link to image</a></p>

<p>Also note the diffenrent boundary references from one part to
underlaying content part.</p>

<p><img src="/media/2982/mailbuil_500x395.jpg"  width="500"  height="395" alt="mailbuil2"/></p>

<p>you can find the code file for this project in the download
section <strong><a href="/media/3005/default.txt">here is a
link.</a></strong></p>

<p>Rememer to change email smtp host and serial for certificat</p>

<p>Note you should implement all the explained methods in nice
class's that wraps all this functionality into one simple class.
The code file you can download is constructed as a simple file so i
would be easier to explain howto encrypt and sign emails. It is not
intended to be used for production purposes.</p>

<p>Finished you now know ho to encrypt and sign mails with c#.</p>

<p>c# encrypting and signing mail</p>
]]></content:encoded></item><item><title>Encrypting  and signing Mail in .Net part 4/5 (Signing the content)</title><link>http://www.umlaut.be/blog/2010/1/18/encrypting--and-signing-mail-in-net-part-45-(signing-the-content).aspx</link><pubDate>Mon, 18 Jan 2010 21:18:10 GMT</pubDate><guid>http://www.umlaut.be/blog/2010/1/18/encrypting--and-signing-mail-in-net-part-45-(signing-the-content).aspx</guid><content:encoded><![CDATA[ 
<p style="display:none">Sending encrypted email - C#</p>

<p>Okay so now we are done and have build the content of the mail.
Now we need to sign it. If you dont want to sign the mail skip this
part and jum straight to encrypting "which will be the next post".
I've found quite a few post on tje net on howto sign at encrypt
mails but none of them worked for me. I've had to look at package
and mail content to analyze how to to build the right content and
signing part as well. For the signing part we off course need a
certificate with access to the private key.</p>

<p><a href="/blog/2010/1/12/encrypting-and-signing-mail-in-net-part-15.aspx"
title="Encrypting and signing Mail in .Net part 1/5">Link to part
1</a>, <a href="/blog/2010/1/13/encrypting-and-signing--mail-in-net-part-25-(retrieving-certificats).aspx"
title="Encrypting and signing Mail in .Net part 2/5 (retrieving certificats)">
part 2,</a> <a href="/blog/2010/1/16/encrypting-and-signing-mail-in-net-part-35-(building-the-content---with-attachments).aspx"
title="Encrypting and signing Mail in .Net part 3/5 (Building the content - with attachments)">
part 3</a></p>

<p><strong>NOTE AGAIN IF THE PROCESS RUNNING THE CODE DOESN'T HAVE
ACCESS TO THE PRIVATE KEY YOU GET A KEYSET DOESN'T MATCH OR PRIVATE
KEY COULD NOT BE FOUND ERROR WHEN TRYING TO SIGN THE
MAIL</strong>.</p>

<p>See earlier post on howo to setup up security for
certificates.</p>

<p>Now finaly to some code. First we gonna make a little helper
method for signing the content. Also note that I use a simple
helper function "GetCert()" all i does is returning the same
certificate since i use the same certificate for signing and
ecrypting. You should offcourse use the methode shown in part 2 of
this series. My get cert is a like but just with an hardcode serial
number. this should be replaced with the serial number for your
certificate.</p>

<p>The little helper function:</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<pre class="brush: c#">
public static X509Certificate2 GetCert()<br />
    {<br />
      //Sets up a new store to look for at certificat in.<br />
      X509Store localStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);<br />
      localStore.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);<br />
<br />
      try<br />
      {<br />
       //NOTE FALSE IS ONLY USED FOR TESTS SHOULD BE CHANGED TO true<br />
<br />
       X509Certificate2Collection matches =<br />
       localStore.Certificates.Find(X509FindType.FindBySerialNumber, "a0 51 bf 0a bc 4a 11 8b 41 9d 56 47 92 b2 34 6c", false);<br />
       if (matches.Count &gt; 0)<br />
         {<br />
           return matches[0];<br />
         }<br />
       else<br />
         {<br />
           return null;<br />
         }<br />
       }<br />
       finally<br />
       {<br />
          localStore.Close();<br />
       }<br />
<br />
     }<br />
</pre>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>And here is how crypting part works. The signature calculation.
Note that the function takes two certifactes one for signing the
mail and the certificates used for encrypting the mail. Theese two
could be the same. But you might have an certificat only for
signing and the you need the extra one for encrypting the mail.</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<pre class="brush: c#">
 public byte[] GetSignature(string message, X509Certificate2 signingCertificate, X509Certificate2 encryptionCertificate)<br />
       {<br />
           byte[] messageBytes = Encoding.ASCII.GetBytes(message);<br />
<br />
           SignedCms signedCms = new SignedCms(new ContentInfo(messageBytes), true);<br />
<br />
           CmsSigner cmsSigner = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, signingCertificate);<br />
           cmsSigner.IncludeOption = X509IncludeOption.WholeChain;<br />
<br />
           if (encryptionCertificate != null)<br />
           {<br />
               cmsSigner.Certificates.Add(encryptionCertificate);<br />
           }<br />
<br />
           Pkcs9SigningTime signingTime = new Pkcs9SigningTime();<br />
           cmsSigner.SignedAttributes.Add(signingTime);<br />
<br />
           signedCms.ComputeSignature(cmsSigner, false);<br />
<br />
           return signedCms.Encode();<br />
       }<br />
</pre>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>With this function we can start adding new boundary to the
content so it will be correct signed. This part was nesscary for
me&nbsp; otherwise i could either encryot the mail or sign it not
both. So before we sign the mail we add som new boundaries and
finaly we gonna add the calculated signature. Again this function
accept the content from we made in the laste post so as input you
could give the method the result from "buildcontent()". Againg note
this is build in simple function so we can got a simple reference
when we wnat to encrypt the content.</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<pre class="brush: c#">
public string signed(string Content)<br />
       {<br />
           string signatureBoundry = "--PTBoundry=2";<br />
           string signatureBoundry2 = "--PTBoundry=3";<br />
               StringBuilder fullUnsignedMessageBuilder = new StringBuilder();<br />
<br />
               fullUnsignedMessageBuilder.Append("Content-Type: ");<br />
               fullUnsignedMessageBuilder.Append("multipart/mixed;");<br />
               fullUnsignedMessageBuilder.Append(" boundary=\"");<br />
           fullUnsignedMessageBuilder.Append(signatureBoundry);<br />
               fullUnsignedMessageBuilder.Append("\"\r\n");<br />
               fullUnsignedMessageBuilder.Append("Content-Transfer-Encoding: ");<br />
   <br />
                fullUnsignedMessageBuilder.Append(TransferEncoding.SevenBit);<br />
               fullUnsignedMessageBuilder.Append("\r\n");<br />
               fullUnsignedMessageBuilder.Append(Content);<br />
<br />
               string fullUnsignedMessage = fullUnsignedMessageBuilder.ToString();<br />
<br />
               byte[] signature = GetSignature(fullUnsignedMessage, GetCert(), GetCert());<br />
<br />
               StringBuilder signedMessageBuilder = new StringBuilder();<br />
<br />
               signedMessageBuilder.Append("--");<br />
               signedMessageBuilder.Append(signatureBoundry2);<br />
               signedMessageBuilder.Append("\r\n");<br />
               signedMessageBuilder.Append(fullUnsignedMessage);<br />
               signedMessageBuilder.Append("\r\n");<br />
               signedMessageBuilder.Append("--");<br />
               signedMessageBuilder.Append(signatureBoundry2);<br />
               signedMessageBuilder.Append("\r\n");<br />
               signedMessageBuilder.Append("Content-Type: application/x-pkcs7-signature; name=\"smime.p7s\"\r\n");<br />
               signedMessageBuilder.Append("Content-Transfer-Encoding: base64\r\n");<br />
               signedMessageBuilder.Append("Content-Disposition: attachment; filename=\"smime.p7s\"\r\n\r\n");<br />
               signedMessageBuilder.Append(Convert.ToBase64String(signature));<br />
               signedMessageBuilder.Append("\r\n\r\n");<br />
     <br />
             signedMessageBuilder.Append("--");<br />
               signedMessageBuilder.Append(signatureBoundry2);<br />
               signedMessageBuilder.Append("--\r\n");<br />
<br />
           return signedMessageBuilder.ToString();<br />
       }<br />
<br />
</pre>

<p>&nbsp;</p>

<p>It is now posssible to return and signed message string ready to
be encrypted by calling :</p>

<p>signed(buildcontent())</p>

<p>&nbsp;</p>

<p>Do note the reference the tells we the content boundary start is
different form the boundary for the signing part, and boundary for
the signature is offcourse the same as for the signing boundary. So
it is important to have acces to the different boundaries for
between each steps. And when we want to encryp the content we also
need the referencs for the signing boundary.</p>

<p>Okay with the content now signed we should be ready to encrypt
the mail and send it see next post Where we also will look at how
the final content should look just before it is send, This will
also help one to build the mailcontent for your own purposes.</p>

<p>Now whe signed the mail.</p>
]]></content:encoded></item><item><title>Encrypting and signing Mail in .Net part 3/5 (Building the content - with attachments)</title><link>http://www.umlaut.be/blog/2010/1/16/encrypting-and-signing-mail-in-net-part-35-(building-the-content---with-attachments).aspx</link><pubDate>Sat, 16 Jan 2010 20:39:42 GMT</pubDate><guid>http://www.umlaut.be/blog/2010/1/16/encrypting-and-signing-mail-in-net-part-35-(building-the-content---with-attachments).aspx</guid><content:encoded><![CDATA[ 
<p style="display:none;">Topic: How to encrypt and sign mail c#.
Signed mail in c#, signing c#, c# send encrypted mail, signed
encrypted mail c#, S/MIME messages</p>

<p>Lets get startet with the real stuff on how to encrypt mail with
c#</p>

<p>Now we have created the certificats and we have the methods for
retrieving them. So before we can sign and encrypt the mail we need
to prepare there content for security operations. When sending
encrypted mail with attachment the content should be included as a
part of the content. If add an attahcment to an email with&nbsp;
using the normal "System.net.mail - message.attachments.add() "
breaks the encryption. To overcome this the attachments are added
to the maincontent of message but seprated with boundries.</p>

<p><a href="/blog/2010/1/12/encrypting-and-signing-mail-in-net-part-15.aspx"
title="Encrypting and signing Mail in .Net part 1/5">Link to part
1</a>, <a href="/blog/2010/1/13/encrypting-and-signing--mail-in-net-part-25-(retrieving-certificats).aspx"
title="Encrypting and signing Mail in .Net part 2/5 (retrieving certificats)">
part 2</a></p>

<p>Since there are different ways to fetch filecontent and
bodycontent i've have focused only on howto message data should be
build, so there are left some work for you to do. Implementing
functions for retrieving filecontent into byte[] fx.</p>

<p>To make the next couple of step easier to connecto to this one
which is the backbone in encrypting the mail, I will make a simple
builcontent() function that builds a simple text/plain mail and
adds an attachment called snebar.jpg placed on the root of my c
drive.</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<pre class="brush: c#">
  <br />
public string buildMessageContent()<br />
{<br />
  string messageBoundry = "--PTBoundry=2";<br />
  StringBuilder message = new StringBuilder();<br />
  message.Append("\r\n");<br />
  message.Append("\r\n");<br />
  message.Append("--");<br />
  message.Append(messageBoundry + "\r\n");<br />
  message.Append("Content-Type: text/plain; charset=us-ascii\r\n"); <br />
  //could use text/html as well here if you want a html message         <br />
  message.Append("Content-Transfer-Encoding: ");<br />
  message.Append(TransferEncoding.QuotedPrintable);         <br />
  message.Append("\r\n\r\n");<br />
  message.Append("TEST AF kryptering")//BODY TEXT GOES HERE<br />
<br />
       <br />
  message.Append("\r\n");<br />
<br />
  //ADD file section<br />
  //could be filename or whatever<br />
  //foreach (string filename in attachments){<br />
  //Read file part implement your own<br />
   byte[] buff = null;<br />
   FileStream fs = new<br />
       FileStream("c:\\snebaer.jpg", FileMode.Open, FileAccess.Read);        <br />
   BinaryReader br = new BinaryReader(fs);<br />
   long numBytes = new FileInfo("c:\\snebaer.jpg").Length;       <br />
   buff = br.ReadBytes((int)numBytes);<br />
   byte[] bytes = buff;<br />
   //Setup filecontent<br />
   String filecontent =<br />
      Convert.ToBase64String(bytes,Base64FormattingOptions.InsertLineBreaks);<br />
<br />
  message.Append("--");<br />
  message.Append(messageBoundry);<br />
  message.Append("\r\n");<br />
  message.Append("Content-Type: ");<br />
  message.Append("application/octet-stream;");<br />
  message.Append("name=c:\\snebaer.jpg");<br />
  message.Append("\r\n");<br />
  message.Append("Content-Transfer-Encoding: base64\r\n\r\n");<br />
  message.Append(filecontent);<br />
  message.Append("\r\n\r\n");<br />
  //} //END FILSECTION<br />
<br />
  message.Append("--");<br />
  message.Append(messageBoundry);<br />
  message.Append("--\r\n");<br />
  return message.ToString();<br />
}<br />
</pre>

<p>&nbsp;</p>

<p>Note that there isout comment foreach loop which could added if
you need to add multiple attachments. I will also be a good idee to
ad at method for building unique boundaries that could be used you
can use Guid or what ever you like. I use theese static one so it
easier to refence them in the next post. the string returned here
is now readyto be signed. Look</p>
]]></content:encoded></item><item><title>Encrypting and signing  Mail in .Net part 2/5 (retrieving certificats)</title><link>http://www.umlaut.be/blog/2010/1/13/encrypting-and-signing--mail-in-net-part-25-(retrieving-certificats).aspx</link><pubDate>Wed, 13 Jan 2010 09:47:17 GMT</pubDate><guid>http://www.umlaut.be/blog/2010/1/13/encrypting-and-signing--mail-in-net-part-25-(retrieving-certificats).aspx</guid><content:encoded><![CDATA[ 
<p>Part two in the series of 5 on howto c# encrypt and sign
mail</p>

<p>So in this post we will looking at howto fetch the security
certs we installed in the last post. There are a few attributes you
can use for this, but for now i'm gonna settle with the serial
number for the certificate.</p>

<p><a href="/blog/2010/1/12/encrypting-and-signing-mail-in-net-part-15.aspx"
title="Encrypting and signing Mail in .Net part 1/5">Link to post
1</a></p>

<p>The serial number can be found on the certificate it self so
open up mmc and add a snap in for the local computer, if you forgot
howto do this have a look in part 1 of series. Once you you found
your recently installed certificate double click the cert and
choose the fan details, click on serial number to allow you to see
the entire key.</p>

<p>&nbsp;</p>

<p><img src="/media/2892/ss_379x476.jpg"  width="379"  height="476" alt="ssss"/></p>

<p>&nbsp;</p>

<p>Okay now we got the serial number.<br />
 now we gonna fetch it out with through .Net</p>

<p>&nbsp;</p>

<pre class="brush: c#">
using System;
using System.Security.Cryptography.Pkcs;
using System.Security.Cryptography.X509Certificates;
using System.Text;
<br />
        /// Finds a certificates on Localmachines  local store based on its serial number
        ///
        /// The serial number of the certificate to retrieve
        /// The requested certificate, or null if the certificate is not found
        public X509Certificate2 FindCertificateFromSerial(string serialNumber)
        {
          //Sets up a new store to look for at certificat in.
          X509Store localStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            localStore.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);<br />

            try
            {
               //NOTE FALSE IS ONLY USED FOR TESTS SHOULD BE CHANGED TO true<br />
                X509Certificate2Collection matches = localStore.Certificates.Find(
                    X509FindType.FindBySerialNumber,
                    serialNumber,
                    false);
           if (matches.Count &gt; 0)
                {
                    return matches[0];
                }
                else
                {
                    return null;
                }
            }
            finally
            {
                localStore.Close();
            }

        }
</pre>

<p>Note the false parameter passed to Certificates.Find this should
be change to true on live system that certificate that has expired
or a like, would also be returned. Also note you need a referencens
to System.Security&nbsp; so you can use the</p>

<pre class="brush: c#">
using System.Security.Cryptography.Pkcs;
</pre>

<p>There are other possible ways to find the certifcate but i leave
that to you find thefindtype that fits your purpose best.</p>
]]></content:encoded></item><item><title>Encrypting and signing Mail in .Net part 1/5</title><link>http://www.umlaut.be/blog/2010/1/12/encrypting-and-signing-mail-in-net-part-15.aspx</link><pubDate>Tue, 12 Jan 2010 08:42:48 GMT</pubDate><guid>http://www.umlaut.be/blog/2010/1/12/encrypting-and-signing-mail-in-net-part-15.aspx</guid><content:encoded><![CDATA[ 
<p>So the following couple of blog post will be about encrypting
mails with attachments.</p>

<p style="display:none;">Topic: How to encrypt and sign mail c#.
Signed mail in c#, signing c#, c# send encrypted mail, signed
encrypted mail c#</p>

<p>Today we start with creating certificates for signing the mails
and encrypting them.</p>

<p>For this to make sensse we need to certificates, one for signing
and on for each reciever of the mail in this example there will be
only one reciever. I will be using win 7 so all screenshots shown
will be from win 7 .</p>

<p>First we create two certificates, we do this by opening the
visual studio command prompt.</p>

<p>the first certificate we create will be the signing certificate
using this line</p>

<p>&nbsp;</p>

<p><em>makecert -n "CN=SigningCert" -ss -sr Currentuser -pe
-r</em></p>

<p><em><br />
</em></p>

<p>This will create a selfsigned certificates where there
privatekey can be exported.</p>

<p>next we will create the certificate for encrypting and
decrypting the mail content.</p>

<p>&nbsp;</p>

<p><em>makecert -n "CN=Encrypting" -ss -sr Currentuser -pe
-r</em></p>

<p>&nbsp;</p>

<p><em><strong>NOTE: CERTIFICATS ARE ONLY VALID FOR
TEST</strong><br />
</em></p>

<p><br />
 Note i've tried installing the certificates on the localmachine
but every time it fails, with a write error, and yes I have logged
in as administrator.</p>

<p>So now we need to setup the certificates for localmachine open
mmc.exe.</p>

<p>Now we add to snap-ins one for the currentuser and one for the
localmachine and snap-in for both should be certificates.</p>

<p>Do this by File-&gt; Add/remove Snap-in</p>

<p>When you are done with this step you should have one snap-in fo
currentuser and one for localmachine see image below</p>

<p>&nbsp;</p>

<p><img src="/media/2859/s2_434x301.jpg"  width="434"  height="301" alt="ss"/></p>

<p>&nbsp;</p>

<p>Next we will export the two certificates, same procedure for
both certificates so i will only do it for the signing certificate
open the currentuser personal certificate find the signingcert
"right mouse click choose copy", next go to the Localcomputer
-&gt;personal-Certificates and choose paste. Volia you should now
be able to se the certificate. in your iis-manger</p>

<p>&nbsp;</p>

<p><img src="/media/2864/s5_378x264.jpg"  width="378"  height="264" alt="s5"/></p>

<p>&nbsp;</p>

<p>HERE starts one of the most important steps i've had and error
one trying to signing mails with a cert where the .Net user doesn't
have acces to the private key.</p>

<p>Right click the certificate. choose&nbsp; All task Manage
Private Keys and give you .Net user full access. Or everyone for
TEST ONLY.</p>

<p>The more correct way to do this step is on your current user
right click your cert choose alltaks export and choose to export
private key. This should work</p>

<p>&nbsp;</p>

<p><img src="/media/2869/2_386x160.jpg"  width="386"  height="160" alt="2"/></p>

<p>&nbsp;</p>

<p><strong>If this step is missing you will get the following error
KEYSET DOES NOT EXIST OR CANNOT FIND PRIVATE KEY<br />
</strong></p>

<p>&nbsp;</p>

<p>&nbsp;</p>
]]></content:encoded></item><item><title>Custom Subitems sorting</title><link>http://www.umlaut.be/blog/2009/11/13/custom-subitems-sorting.aspx</link><pubDate>Fri, 13 Nov 2009 12:47:09 GMT</pubDate><guid>http://www.umlaut.be/blog/2009/11/13/custom-subitems-sorting.aspx</guid><content:encoded><![CDATA[ 
<p>Subitems sorting in sitecore only works for some of predefined
fields. But it is an easy task to sort items for none
standardfields. Subitems sorting is found in Sorting dialog
here</p>

<p><img src="/media/2472/sorting.jpg" width="261" height="112" alt="sorting"/></p>

<p>&nbsp;</p>

<p>First you need to create your own subitem sorting. This can be
found in the master database under system/setting/subitems
sorting</p>

<p>Easiest thing to do is just to duplicate one of the existing
items and edit the duplicated item.</p>

<p>The name of the items will be shown in the sorting list so give
i a meaning full name, i choose own created as an example. Bad name
!</p>

<p><img src="/media/2477/sortingitem.jpg" width="190" height="313" alt="subsorting"/></p>

<p>&nbsp;</p>

<p>You need to specifiy in which assambly your compare class is
presented in.</p>

<p>This is done in the Data-section.</p>

<p><img src="/media/2486/dlllink_500x114.jpg"  width="500"  height="114" alt="defiinedll"/></p>

<p>So for this example we created a our own date field but not all
items derives from a template that gives acces to this field, so as
a fallback we look at the sitecore __created field "standard field
under statistics.</p>

<p>The keypart is the DoCompare function in the following code</p>

<pre class="brush: c#">
namespace PT.SubItemsSorter
{
 public class CreatedComparer : Comparer
 {<br />
 /// &lt;summary&gt;
 /// Initializes a new instance of the &lt;see cref="CreatedComparer"/&gt; class.
 /// &lt;/summary&gt;<br />
 /// &lt;remark&gt;Created 13-11-2009 11:55 by ts&lt;/remark&gt;
 public CreatedComparer(
 
 }

// Methods
 protected override int DoCompare(Item item1, Item item2)
 {
 return GetCreatedDate(item2).CompareTo(GetCreatedDate(item1));
 }

 /// &lt;summary&gt;
 /// Gets the created date.
 /// &lt;/summary&gt;
 /// &lt;param name="item"&gt;The item.&lt;/param&gt;
 /// &lt;returns&gt;&lt;/returns&gt;
 /// &lt;remark&gt;Created 13-11-2009 11:55 by ts&lt;/remark&gt;
 private DateTime GetCreatedDate(Item item)
 {
 if (String.IsNullOrEmpty(item[DatasourceCreatedField])
 return  GetDate(item,SitecoreCreatedDateField);
 return GetDate(item, DatasourceCreatedField);
 }

/// &lt;summary&gt;
 /// Gets the date.
 /// &lt;/summary&gt;
 /// &lt;param name="item"&gt;The item.&lt;/param&gt;
 /// &lt;param name="field"&gt;The field.&lt;/param&gt;
 /// &lt;returns&gt;&lt;/returns&gt;
 /// &lt;remark&gt;Created 13-11-2009 11:55 by ts&lt;/remark&gt;
 private DateTime GetDate(Item item,string field)
 {
 DateField dateField = ((DateField)item.Fields[field]);
 return dateField.DateTime;
 }

private const string DatasourceCreatedField = "DataSource_CreatedDate";
 private const string SitecoreCreatedDateField = "__Created";
 }
}
</pre>

<p>Now you should be able to se it in the subitems sorting list.
The code gives you the newest first.</p>

<p><img src="/media/2493/sortingdialog_347x404.jpg"  width="347"  height="404" alt="alldonesorting"/></p>

<p>&nbsp;</p>
]]></content:encoded></item><item><title>Shortcuts in sitecore revisited</title><link>http://www.umlaut.be/blog/2009/11/11/shortcuts-in-sitecore-revisited.aspx</link><pubDate>Wed, 11 Nov 2009 11:07:35 GMT</pubDate><guid>http://www.umlaut.be/blog/2009/11/11/shortcuts-in-sitecore-revisited.aspx</guid><content:encoded><![CDATA[ 
<p>Here is another way to add new shortcuts to the sitecore shell.
This method doesn't use the global keys.xml file but set shortcuts
on item level. So if we use the same example as my last entry with
shortcuts "we want to bind a shortcut to preview".</p>

<p>Go into Core database, Find the item "I've sorted my items so
publish is first"</p>

<p><img src="/media/2386/chuncks_275x397.jpg"  width="275"  height="397" alt="Path"/></p>

<p>&nbsp;</p>

<p>Now dind the datatab a field KeyCode put in your favortie
keycode for thuis example we will bind F10 (keycode 121).</p>

<p><img src="/media/2391/keycode_497x270.jpg"  width="497"  height="270" alt="keycode"/></p>

<p>&nbsp;</p>

<p>Now you should be able to start the preview by hitting F10.</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>
]]></content:encoded></item><item><title>Create new shortcuts in sitecore</title><link>http://www.umlaut.be/blog/2009/11/6/create-new-shortcuts-in-sitecore.aspx</link><pubDate>Fri, 06 Nov 2009 11:42:43 GMT</pubDate><guid>http://www.umlaut.be/blog/2009/11/6/create-new-shortcuts-in-sitecore.aspx</guid><content:encoded><![CDATA[ 
<p>A usefull little thing could be to create your own shortcuts
keys in sitecore.<br />
 Of course one should be carefull not to override keys allready
assigned.</p>

<p>In the file:</p>

<p>sitecore\shell\Controls\Applications\Global Keys.xml</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<pre class="brush: xml;">
 
&lt;?xml version="1.0" encoding="utf-8" ?&gt;<br />
&lt;control xmlns:def="Definition" xmlns="http://schemas.sitecore.net/Visual-Studio-Intellisense"&gt;
  &lt;GlobalKeys&gt;
    &lt;RegisterKey KeyCode="120" Click="system:publish"/&gt;
    &lt;KeyMap/&gt;
  &lt;/GlobalKeys&gt;
&lt;/control&gt;
</pre>

<p>&nbsp;</p>

<p>Simple xml with registered shortcuts for the desktop, you can
add your own.<br />
 So for example we want to add F10 as a shortcut for preview we add
the line.</p>

<p>&nbsp;</p>

<pre class="brush: xml;">
 
&lt;RegisterKey KeyCode="121" Click="system:preview"/&gt;
</pre>

<p>&nbsp;</p>

<p>You can finde more keycodes <a
href="http://www.webonweboff.com/tips/js/event_key_codes.aspx"
target="_blank" title="keycodes">here</a></p>

<p>&nbsp;</p>
]]></content:encoded></item></channel></rss>
