Incorrect results while decrypting AES-128-ECB text

832 Views Asked by At

I have a piece of Base64 text, which I know was encrypted in AES-128-ECB mode, and even know the key (YELLOW SUBMARINE, 16 bytes). I'm using the following code to decrypt it.

textbox1 contains cyphertext;

textbox2 contains the key

    private void button6_Click(object sender, EventArgs e)
    {
        Byte[] CTBytes = System.Convert.FromBase64String(textBox1.Text);            
        Byte[] KeyBytes = new Byte[textBox2.TextLength];
        string Key = textBox2.Text;
        Aes Decryptor = Aes.Create();
        Decryptor.Mode = CipherMode.ECB;
        Decryptor.BlockSize = 128;
        for (int iCounter = 0; iCounter < textBox2.Text.Length; iCounter++)            
            KeyBytes[iCounter] = Convert.ToByte(textBox2.Text[iCounter]);          
        Decryptor.KeySize = KeyBytes.Length * 8;
        Decryptor.Key = KeyBytes;            
        Decryptor.Padding = PaddingMode.None;
        ICryptoTransform Decr = Decryptor.CreateDecryptor();
        Byte[] plainText = null;
                    using (MemoryStream ms = new MemoryStream())
        {
            using (CryptoStream cs = new CryptoStream(ms, Decr, CryptoStreamMode.Write))
            {
                cs.Write(CTBytes, 0, CTBytes.Length);
            }

            plainText = ms.ToArray();
        }                        
        string s = System.Text.Encoding.ASCII.GetString(plainText);
        textBox3.Text = s;
        string s1 = System.Text.Encoding.Unicode.GetString(plainText);
        textBox2.Text = s1;
    }

The result, however, is incorrect (meaningless). Is there something I've missed? I can provide the cyphertext as well if that's necessary.

Update: the ciphertext

U2FsdGVkX1+V1HkNnBtngUKxuppRFBa0cxtj5jwMcQsgxA+WdPK2JtNCHIyJ4xyj
TABANu/jEXSigEG8NiVczGSkWipGV1rVT3+QmrQAAToAm68BR9ldVHG2IUpwN20s
rKi6bcSNKk7+w9YoSrkO8eX9JEiBvgAUxNrdShY/K7BUFKkwr0y/kJAo9w2wy9vA
7RjUKggwe3DSm/OIrs+yOTUGo0lla0PdF9jwsOraVX6HeAFT8bfAaKFGXqKgzYKZ
KfAoP4qQdg2qWH1FohCsxTMPg6VpjSZo5c21RubgBm3pwdIHibhapFv+9xkgCt6C
y4LL2iaBc+WzCjezYPvXD3GGJjhI1dtDWs9ihoGLh6EBe9Nj9A8Aoi2U2jcNrbkD
PPtYR1vwsYurt20YPqOAUxdytquANgHXQPs74M4MLoHkjmZALQ2TFVFUb4tZXpEe
U7Dv/3uJkz1Exnmona4D4pdrlEgALqPftmUaC7EDWLa9WGPYeYPO0ktD9uEBiATS
HZM7i6erQgVdh1zsNPa4+vhOdSf5EdOW3MrXFMqns/M6foO3tA60JDBhDzwdmzTq
HEgaSPNU6rbhEtUcdzOoPwT5zw5mJr01Y46CRliNz2Hbg/Q+no5sPdolJBO6VL/v
FHf29rkPv0r/yIm4jTCtgzJRTJ0twWl0WvsSWh8E11AQh7rrAq+5aUMr5+CfZq5E
/nGEM5e9rx/oMZ68T6Rwz9oXE+kJazUt5ipj/ccu1P/HlCcRHXa2tt7o+tS+koN4
F60UdRm4ExoeWKRhpD93Xlf22GFKST8abA/cRjFSLwiB+oI0vZLXQ6FFz2F9Iogl
eXxjIx7JUpOsYYxgnUzznffzMT33p5GivXWE91LU7sptRtSDpmrn1UUhjE+KkFGi
hAOAjMzqG7Oos5V1h8SQaBug2yk4H2GX9SkBtLul6YU=
0

There are 0 best solutions below