0

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#?

spaghettifunk
  • 1,936
  • 4
  • 24
  • 46
user2764359
  • 127
  • 3
  • 18
  • Your question title has been edited, see why: http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles – Arin Ghazarian Jan 10 '14 at 08:59
  • Have you tried... to actually decrypt? Your code only does the download. – DarkWanderer Jan 10 '14 at 09:08
  • @DarkWanderer I don't know how to do the decryption, that is what I am asking. – user2764359 Jan 10 '14 at 09:10
  • @DarkWanderer Would I just have to call the Decrypt method that is on that link? Where would I call it in my download code? After I call reader.ReadBytes(1 * 1024 * 1024 *10)? – user2764359 Jan 10 '14 at 11:33
  • user2764359 - just bike shedding here, but your encryption will leak information just like Tux the Penguin at [Electronic Codebook (ECB)](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_codebook_.28ECB.29). – jww Jan 11 '14 at 05:32
  • @noloader Thanks for the link, that is some handy information. However, I am not too worried about that as the default service that uses this doesn't leak information, and I'm doing the exact same thing that does, just through C# code instead of an iOS application. I am still trying to figure out how to decrypt this though...I have had no help so far. – user2764359 Jan 11 '14 at 09:49
  • This question appears to be off-topic because it does not show any C# decryption code (I'm waiting for the "darn you user, you haven't tried anything yourself" reason to reappear). – Maarten Bodewes Jan 12 '14 at 02:58

0 Answers0