Decryption of string in C#

//This class is for decrypt the encrypted value
//call this method with two parameters text and key "01AB=$6Q"

class DecryptClass

public static string Decrypt(string text, string key)

byte[] encodedkey;
byte[] iv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
byte[] bytes;

encodedkey = Encoding.UTF8.GetBytes(key);
DESCryptoServiceProvider csp = new DESCryptoServiceProvider();

bytes = Convert.FromBase64String(text);

MemoryStream ms = new MemoryStream();

CryptoStream cs = new CryptoStream(ms, csp.CreateDecryptor(encodedkey, iv),CryptoStreamMode.Write);
cs.Write(bytes, 0, bytes.Length);
catch (Exception ex)

return Encoding.UTF8.GetString(ms.ToArray());




Author: Amit Srivastava15 Apr 2009 Member Level: Bronze   Points : 1

This code complements the previous encryption code by Shivshankar. All things encrypted, must be decrypted. Here also if some explanation about classes, methods and namespaces is provided i (and other visitors) would have benfitted in a better way by your article sir.

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: