1. 程式人生 > 其它 >Unity 獲得檔案的MD5值的方法

Unity 獲得檔案的MD5值的方法

技術標籤:UnityC#unity

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); } } }