Category Archives: Dot Net

Run asp.net on ubuntu 12.10 linux

Thanks to mono we can run asp.net on our linux machines (i have to test some asp.net code), to do that we will use XSP, here the description took it from mono website.

XSP is a standalone web server written in C# that can be used to run your ASP.NET applications with minimal effort. XSP works under both the Mono and Microsoft runtimes. The code is available from our download page (look for XSP web server) or from the Anonymous SVN repository (module name: xsp).

To nstall it:

  1.  
  2. #install XSP
  3. sudo apt-get install mono-xsp2
  4.  
  5. # i have to use vb.net so, i installed the Visual Basic.NET Compiler
  6. sudo apt-get install mono-vbnc
  7.  

Once installed, just start XSP from the directory where your code is located, after that you can browse to http://localhost:8080 to see your web pages

  1.  
  2. $ cd /home/rene/asp/
  3. $ xsp2
  4. xsp2
  5. Listening on address: 0.0.0.0
  6. Root directory: /usr/share/asp.net2-demos
  7. Listening on port: 8080 (non-secure)
  8. Hit Return to stop the server.
  9. Application_Start
  10.  

Crypting data using 3des on c#

Today i have to use c# to crypt some data using 3des, so here is a pretty basic example to do it, i test it using mono.

  1.  
  2. using System;
  3. using System.Security.Cryptography; // used for TripleDESCryptoServiceProvider
  4. using System.Text; // used for Encoding.ASCII.GetBytes
  5.  
  6. public class Test
  7. {
  8.         static public void Main ()
  9.         {
  10.                 TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); // i create the 3des object
  11.                 byte[] key = Encoding.ASCII.GetBytes("123456781234567812345678"); // the key should be 24 chars long
  12.                 string data = "Here goes the data to encrypt";
  13.                 des.Mode = CipherMode.CBC; // We’ll use CBC
  14.                 des.Key = key; // I set the key
  15.                 byte[] iv = des.IV; // I store the randomly generated IV since i will need for decrypt
  16.                 byte[] inputArray = UTF8Encoding.UTF8.GetBytes(data);
  17.                 ICryptoTransform cTransform = des.CreateEncryptor();
  18.                 byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
  19.                 // i will print as readble data
  20.                 Console.WriteLine( (Convert.ToBase64String(resultArray)) );
  21.                 Console.WriteLine( (Convert.ToBase64String(iv)) );
  22.         }
  23. }
  24.  
  25.