Unity 獲得檔案的MD5值的方法
阿新 • • 發佈:2021-01-23
1、
cmd : certutil -hashfile 檔案path
2、程式碼的方式
using System;
using System.IO;
using System.Text;
using UnityEngine;
using System.Security.Cryptography;
public class MD5Test: MonoBehaviour
{
private StringBuilder _stringBuilder;
private void Start()
{
_stringBuilder = new StringBuilder();
try
{
// 找到指定檔案
var fs = new FileStream(Application.streamingAssetsPath + "/AssetBundles/pannel", FileMode.Open);
MD5 md5 = new MD5CryptoServiceProvider();
var retVal = md5.ComputeHash(fs);
fs.Close ();
foreach (var t in retVal)
{
_stringBuilder.Append(t.ToString("X"));
}
Log.Debug(_stringBuilder);
}
catch (Exception ex)
{
throw new Exception("Get File MD5 Fail, error:" + ex.Message);
}
}
}