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. // i create the 3des object
  6.                 byte[] key = Encoding.ASCII.GetBytes("123456781234567812345678"); // the key should be 24 chars long
  7. "Here goes the data to encrypt";
  8.                 des.Mode = CipherMode.CBC; // We’ll use CBC
  9.                 des.Key = key; // I set the key
  10.                 byte[] iv = des.IV; // I store the randomly generated IV since i will need for decrypt
  11. // i will print as readble data

One thought on “Crypting data using 3des on c#

Leave a Reply

Your email address will not be published. Required fields are marked *