Unity3d the MD5 of the generated files of the generic tool class

Source: Internet
Author: User

Today we write the tool class, what is the use of this class?

That is, no matter what project you do, this tool class can be used, the reason is universal, is applicable to all projects.

This section I mainly talk about how to generate the file MD5 code.

Then this MD5 is what a ghost thing, the reader can own Baidu, in fact, the brief is to verify whether the file has been tampered with.

What do you mean, like when you go to the website to download the game client software, when some hackers like to do something bad, in your client add some malicious code and so on.

When the hacker changed the client file, the MD5 of the file also changed. So we just need to verify that the user downloads the client's MD5 and the MD5 code provided by the website is consistent, to determine whether to download.

So this MD5 is very useful, and C # also comes with the MD5 library.

public static string BuildFileMd5 (string filename)        {            string filemd5 = null;            Try            {                using (var fileStream = file.openread (filename))                {                    var md5 = MD5. Create ();                    var filemd5bytes = MD5. ComputeHash (FileStream);//Calculates the hash value of the specified Stream object                                                          filemd5 = FormatMD5 (filemd5bytes);}            }            catch (System.Exception ex)            {                loggerhelper.except (ex);            }            return filemd5;        }
        public static string FormatMD5 (byte[] data)        {            return System.BitConverter.ToString (data). Replace ("-", ""). ToLower ();//replace byte[] with a string        }

Write this code into the Utils class, and later, if you want to use the MD5 code to calculate the direct utils.buildfilemd5 (path), you can take the MD5 of this file.

is not very simple, OK, then I will continue to update some of the common tool methods used.

Unity3d the MD5 of the generated files of the generic tool class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.