unity MD5

获取文件的Md5值

        public string GetFileHash(string filePath)
        {
            if (!IsFileExist(filePath))
            {
                return "";
            }

            try
            {
                byte[] data = readFile(AssetBundleReader.mWritablePath + filePath);
                return getDataHash(data);
            }
            catch (FileNotFoundException e)
                return null;
            }
        }

        public string GetDataHash(byte[] data)
        {
            try
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] result = md5.ComputeHash(data);
                string fileMD5 = "";
                foreach (byte b in result)
                {
                    fileMD5 += System.Convert.ToString(b, 16).PadLeft(2, '0');
                }
                return fileMD5;
            }
            catch (FileNotFoundException e)
            {
                return null;
            }
        }

猜你喜欢

转载自blog.csdn.net/u012909508/article/details/83015179
MD5
今日推荐