当前位置:首页 > 开发 > C# > 正文内容

C# 获取MD5

C#4年前 (2022-10-30)
命名空间    
using System.Security.Cryptography;


GetMd5    
        public static string GetMd5(string filePath)
        {
            try
            {
                StringBuilder sb = new StringBuilder();

                using (FileStream file = new FileStream(filePath, FileMode.Open))
                {
                    MD5 md5 = new MD5CryptoServiceProvider();
                    byte[] retVal = md5.ComputeHash(file);
                    foreach (byte item in retVal)
                    {
                        sb.Append(item.ToString("x2"));
                    }
                    md5.Dispose();
                }
                return sb.ToString().ToUpper();
            }
            catch (Exception)
            {
            }
            return String.Empty;
        }


GetMd5    
        public static string GetMd5(byte[] bits)
        {
            try
            {
                
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] retVal = md5.ComputeHash(bits);
                md5.Dispose();
                StringBuilder sb = new StringBuilder();
                foreach (byte item in retVal)
                {
                    sb.Append(item.ToString("x2"));
                }
                return sb.ToString().ToUpper();
            }
            catch (Exception)
            {
            }
            return String.Empty;
        }




转载请注明出处。

本文链接:http://www.pythonopen.com/?id=238

返回列表

上一篇:C# MDI例子

下一篇:C# 冒泡排序

相关文章

C#解析Torrent获取磁力链

NuGet添加 MonoTorrentusing MonoTorrent;string&n...

C# 冒泡排序

int[] iage = { 11, 55,&nb...

C# double转为string并保留两位小数

在 C# 中,可以使用多种方式将 double 类型的数据转换为 string 类型并保留两位小数,...

C# Browsable(bool)

在编程中(比如常见的 C# 语言在开发 Windows Forms 等应用程序时),Browsabl...

C# OnMeasureItem

1. **整体功能概述**   - `OnMeasureItem` 是一个在Wi...

c# Invalidate、Refresh、Refreshitem、Refreshitems的功能

Invalidate方法功能概述Invalidate方法主要用于使控件的特定区域(整个控件或部分区域...