Unity 计算文件MD5

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Security.Cryptography;
using System;
using System.IO;
using System.Text;

public class Md5Test : MonoBehaviour
{
    
    
    
    // Start is called before the first frame update
    void Start()
    {
    
    
        
    }

    // Update is called once per frame
    void Update()
    {
    
    
        if(Input.GetKeyDown(KeyCode.Escape))
        {
    
    

        }
    }

    [MenuItem("Custom Editor/MD5")]
    private static void GetMD5()
    {
    
    
        var path = EditorUtility.OpenFilePanel("", "", "lua");
        FileStream file = new FileStream(path, System.IO.FileMode.Open);
        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] retVal = md5.ComputeHash(file);
        file.Close();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < retVal.Length; i++)
        {
    
    
            sb.Append(retVal[i].ToString("x2"));
        }
        Debug.Log(sb.ToString());
    }
}

Guess you like

Origin blog.csdn.net/qq_41179365/article/details/119389271