zoukankan      html  css  js  c++  java
  • 文件MD5 并复制到剪切板

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace FileMd5
    {
        public partial class GetMd5 : Form
        {
            public GetMd5()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                button1Md5.Text = "Get MD5";
            }
    
            /// <summary>
            /// 获取文件MD5值
            /// </summary>
            /// <param name="fileName">文件绝对路径</param>
            /// <returns>MD5值</returns>
            public static string GetMD5(string fileName)
            {
                try
                {
                    FileStream file = new FileStream(fileName, FileMode.Open);
                    System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.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"));
                    }
                    return sb.ToString();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
    
            private void Button1_Click(object sender, EventArgs e)
            {
                try
                {
                    button1Md5.Text = "ing";
                    string strMd5 = GetMD5(textBox1Path.Text.ToString().Trim());
                    Clipboard.SetDataObject(strMd5);
                    textBox2Md5.Text = "已复制到剪切板      " + strMd5;
    
    
                }
                catch (Exception ex)
                {
                    textBox2Md5.Text = "err";
                }
                finally
                {
                    button1Md5.Text = "Get MD5";
                }
            }
        }
    }
  • 相关阅读:
    在Linux中安装Oracle(较详细图解)
    SecureCRT
    MHA配置文件说明
    MySQL建表规范与常见问题 (go)
    Shell编程时常用的系统文件(转)
    Leetcode: Excel Sheet Column Title
    Leetcode: Find Peak Element
    Leetcode: Intersection of Two Linked Lists
    Leetcode: Majority Element
    Summary: Class Variable vs. Instance Variable && Class Method
  • 原文地址:https://www.cnblogs.com/2eggs/p/12698639.html
Copyright © 2011-2022 走看看