Getting an image from Wikipedia API. MD5 of the image name not same as wikipedia md5 code.

Hello, I am trying to get images from wikipedia API. API only gives name of the files. According to here wikipedia encodes filename with md5 and puts it under:

http://upload.wikimedia.org/wikipedia/commons/FIRST_CHAR_MD5/FIRST_TWO_CHAR_MD5/FILE_NAME

But when i try to encode filenames with c#'s md5 algorithm i get different md5 hash code. How can i get same hashcode?

        System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
        md5.Initialize();
        byte[] buffer = System.Text.Encoding.ASCII.GetBytes(filename);
        byte[] bufferEncrypt = md5.ComputeHash(buffer, 0, buffer.Length);
        string pwdX = System.Convert.ToBase64String(bufferEncrypt);
        md5.Clear();
		byte[] bytes = System.Convert.FromBase64String(pwdX); 
        StringBuilder sb = new StringBuilder(); 
        foreach (byte b in bytes) 
             sb.Append(b.ToString("x2")); 
        print (sb.ToString()); 

EDIT: Seems like the problem is with the specific characters like “% ü …”.

  1. Visit: Paj's Home: Cryptography: JavaScript MD5
  2. Enter Spelterini_Blüemlisalp.jpg into the text box. (Note that the space has been replaced by an underscore exactly as the wikimedia commons page suggests.)
  3. Click MD5 button
  4. Observe result starts with ae exactly as wikimedia commons pages says

So, consider using the Javascript code from Paj’s website in your Unity project. Note also, that you will need to URL encode the filename when you request the resource. (The MD5 part does not need this encoding, just replace spaces with underscores.)