Skip to content

Encryption/Decryption not working

dylan

Asked Nov 10, 2010, 11:07 PM EST1 answer
Share
LinkedInX
This code isnt giving me the correct text decrypted...
C#
 private void Encrypt(object sender, EventArgs e)
        {
            string keystring = Key.Text.Trim();
            byte[] key = Encoding.Unicode.GetBytes(keystring);
            byte[] input = Encoding.Unicode.GetBytes(EnterText.Text);
            string returnstring = "";
            int keyindex = 0;
            int counter = 0;
            foreach (byte CHAR in input)
            {
                returnstring += (char)(CHAR + 10);
                keyindex++;
                counter++;
            }
            Return.Text = returnstring;
        }

        private void Decrypt(object sender, EventArgs e)
        {
            string keystring = Key.Text.Trim();
            byte[] key = Encoding.Unicode.GetBytes(keystring);
            byte[] input = Encoding.Unicode.GetBytes(EnterText.Text);
            string returnstring = "";
            int keyindex = 0;
            int counter = 0;
            foreach (byte CHAR in input)
            {
                returnstring += (char)(CHAR - 10);
                keyindex++;
                counter++;
            }
            Return.Text = returnstring;
        }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi,
    code for encryption:
    using System.Security.Cryptography;
    MD5 md = new MD5CryptoServiceProvider();
    UTF8Encoding encoder = new UTF8Encoding();

    byte[] hash = md.ComputeHash(encoder.GetBytes(textBox1.Text));
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < hash.Length - 1; i++)
    {
    sb.Append(hash[i].ToString("X2"));
    }
    label1.Text = sb.ToString();
    MD5 is used for secure purpose we are not able to decrypt it.
     
     
    0