Steps to reproduce the unexpected result:
- Using http://aesencryption.net/ I encrypt the text
HappyCodingwithyecpPqAJ+PnBMtggWVz42WME3TjhG313OhvBuUJOFtc=as the key and256-Bitoption chosen in the drop-down. I receiveLox/sfjNyXOzP9ZE8Fjj9REcuB+iJ1EXXuNjf2du29c=as a result. I then run it through the Decrypt function in my code:
var testAesString = "Lox/sfjNyXOzP9ZE8Fjj9REcuB+iJ1EXXuNjf2du29c="; var decryptedString = Decrypt(testAesString, key);and receive
"�ГYC���{R\u0017V��@\u0013�NH�$�|�\u001a)˪n�mp"instead of "HappyCoding"
The code for the Decrypt function is below:
private static string Decrypt(string stringCypher_Text, string stringKey) { Byte[] Key = Convert.FromBase64String(stringKey); Byte[] Cypher_Text = Convert.FromBase64String(stringCypher_Text); RijndaelManaged Crypto = null; MemoryStream MemStream = null; ICryptoTransform Decryptor = null; CryptoStream Crypto_Stream = null; StreamReader Stream_Read = null; string Plain_Text; try { Crypto = new RijndaelManaged(); Crypto.Padding = PaddingMode.Zeros; Crypto.Key = Key; Crypto.BlockSize = 256; Crypto.Mode = CipherMode.ECB; Crypto.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Decryptor = Crypto.CreateDecryptor(Crypto.Key, Crypto.IV); MemStream = new MemoryStream(Cypher_Text); Crypto_Stream = new CryptoStream(MemStream, Decryptor, CryptoStreamMode.Read); Stream_Read = new StreamReader(Crypto_Stream); Plain_Text = Stream_Read.ReadToEnd(); } finally { if (Crypto != null) Crypto.Clear(); MemStream.Flush(); MemStream.Close(); } return Plain_Text; } I am not receiving any errors. I am receiving an unexpected result. I don't know how to approach this in regards to testing it further. My thought is maybe the website I am using to receive the encrypted values in the first place is using different settings etc.
Any direction on how to test and/or resolve is appreciated.