Click here to Skip to main content
15,889,887 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
hai...
i have try this code to encrypt a string and decryption also...
i am facing error in method calls...

the following code i have error...
can you give me solution to debug the error...

protected void Page_Load(object sender, EventArgs e)
   {
       InitializeComponent();
   }

   protected void Button1_Click(object sender, EventArgs e)
   {
       byte[] buffer = Encryption(textBox1.Text, txtKey.Text);
       string b = Convert.ToBase64String(buffer);
       textBox1.Text = b;
   }
   public static byte[] Encryption(string PlainText, string key)
   {
       TripleDES des = CreateDES(key);
       ICryptoTransform ct = des.CreateEncryptor();
       byte[] input = Encoding.Unicode.GetBytes(PlainText);
       return ct.TransformFinalBlock(input, 0, input.Length);
   }
   public static string Decryption(string CypherText, string key)
   {
       byte[] b = Convert.FromBase64String(CypherText);
       TripleDES des = CreateDES(key);
       ICryptoTransform ct = des.CreateDecryptor();
       byte[] output = ct.TransformFinalBlock(b, 0, b.Length);
       return Encoding.Unicode.GetString(output);
   }
   static TripleDES CreateDES(string key)
   {
       MD5 md5 = new MD5CryptoServiceProvider();
       TripleDES des = new TripleDESCryptoServiceProvider();
       des.Key = md5.ComputeHash(Encoding.Unicode.GetBytes(key));
       des.IV = new byte[des.BlockSize / 8];
       return des;
   }
   protected void Button2_Click(object sender, EventArgs e)
   {
       textBox2.Text = Decryption(textBox1.Text, txtKey.Text);
       //textBox3.Text = Decryption(textBox2.Text, txtKey.Text);
   }
Posted
Updated 26-Nov-11 18:33pm
v2
Comments
[no name] 27-Nov-11 0:35am    
Always format code snippets with pre tag
[no name] 27-Nov-11 0:36am    
What is the error? Do you expect us to know intuitively from reading this snippet every possible error that can occur and which specific one you are getting?
Raghupathiraja 27-Nov-11 0:51am    
CS0103: The name 'InitializeComponent' does not exist in the current context
Hari Om Prakash Sharma 27-Nov-11 1:30am    
Debug code in console application
[no name] 27-Nov-11 1:38am    
Irrelevant and unhelpful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900