I'm making a small application for fun in C# which retrieves a image from a server which is encrypted using AES/ECB with a single synchronous key (which I know) and padded using PKCS#5.
I tried just downloading the image by using a BinaryReader, however when I go to open the image, it is a corrupt file. I assume this is because it is encrypted. Here is my code:
string repsonseData = string.Empty;
using (var response = (HttpWebResponse)req.GetResponse())
{
using (var reader = new BinaryReader(response.GetResponseStream()))
{
Byte[] lnByte = reader.ReadBytes(1 * 1024 * 1024 * 10);
using (FileStream lxFS = new FileStream("imageName.jpg", FileMode.Create))
{
lxFS.Write(lnByte, 0, lnByte.Length);
}
}
}
The synchronous key is: M02cnQ51Ji97vwT4 Any help would be appreciated. Thanks!
EDIT: I found this piece of PHP code which does what I need:
public function decryptECB($data)
{
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, self::BLOB_ENCRYPTION_KEY, self::pad($data), MCRYPT_MODE_ECB);
}
The BLOB_ENCRYPTION_KEY is the key that I provided above. Could somebody convert that to C#?