- Home /
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 "% ü .....".
Answer by Graham-Dunnett · Jul 02, 2013 at 11:49 AM
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.)Click MD5 button
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.)
Thanks Graham, but my whole code is written in c# and i can't include another file to the project.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to change the color of an image every two seconds 1 Answer
deactivate Image(script) component on gameobject c# 1 Answer
Error facebook profile picture 1 Answer