• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by srcan · Jul 02, 2013 at 08:32 AM · c#imagecryptographymd5

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 "% ü .....".

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Graham-Dunnett · Jul 02, 2013 at 11:49 AM

  1. Visit: http://pajhome.org.uk/crypt/md5/index.html

  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 t$$anonymous$$s encoding, just replace spaces with underscores.)

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image srcan · Jul 02, 2013 at 11:53 AM 0
Share

Thanks Graham, but my whole code is written in c# and i can't include another file to the project.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

The name MD5Test does not exist in the current context 2 Answers

How to change colors in unity using photon? 0 Answers

Initialising List array for use in a custom Editor 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges