I have a function which try to decyrpt a byte array in C#.
Decryption function:
string Decrypt(byte[] cipherText, byte[] Key, byte[] IV)
{
string plaintext = null;
// Create AesManaged
using (AesManaged aes = new AesManaged())
{
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.None;
// Create a decryptor
ICryptoTransform decryptor = aes.CreateDecryptor(Key, IV);
// Create the streams used for decryption.
using (MemoryStream ms = new MemoryStream(cipherText))
{
// Create crypto stream
using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
{
// Read crypto stream
using (StreamReader reader = new StreamReader(cs))
plaintext = reader.ReadToEnd();
}
}
}
return plaintext;
}
Below is how I implement the function:
byte[] app_key = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 };
byte[] data = { 0xB6 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x73 ,0x69 ,0x2D ,0x01 ,0x00 ,0x01 ,0x18 ,0x4F ,0x84 ,0xE8 };
var sts = Decrypt(data, app_key, new byte[16]);
Console.WriteLine(BitConverter.ToString(Encoding.ASCII.GetBytes(sts)));
But the output is 3F-3F-2F-31-3F-3F-3F-5E-61-2A-21-42-3F-2B which is wrong!!!
The correct output is d4-f7-2f-31-a3-a8-d4-a3-5e-61-2a-21-42-88-2b-dc.
What am I doing wrong here? Is there any other AES128 decryption function?
Thanks...