zoukankan      html  css  js  c++  java
  • C# MD5

    没什么好写的

        static class MyMD5
        {
            public static string GetMD5Hash(string Message,bool MD5_Mode)
            {
                try
                {
                    byte[] result = Encoding.Default.GetBytes(Message);
                    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                    byte[] output = md5.ComputeHash(result);
                    if (MD5_Mode == true) return BitConverter.ToString(output).Replace("-", "");//32位MD5值
                    else return BitConverter.ToString(output, 4, 8).Replace("-", "");           //16位MD5值
                }
                catch { MessageBox.Show("校验失败");return ""; }
    
            }
            public static string GetMD5HashFromFile(string fileName,bool MD5_Mode)
            {
                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"));
                    }
                    if(MD5_Mode==true) return sb.ToString().ToUpper();
                    else return sb.ToString().Substring(8, 16).ToUpper();
    
                }
                catch { MessageBox.Show("校验失败"); return ""; }
            }
        }
    MyMD5
  • 相关阅读:
    Oracle分析函数
    oracle row_number的使用
    lru缓存测试类
    注解测试类
    lucene测试类
    SVN中检出(check out) 跟导出(export) 的区别
    Lucene原理与代码分析
    Lucene入门基础教程
    linux的less命令
    day4 大纲笔记
  • 原文地址:https://www.cnblogs.com/xzhblogs/p/5799079.html
Copyright © 2011-2022 走看看