导航

yaosansi's Blog

当你背向太阳的时候,你只会看到自己的阴影!能力是有限的,努力无限的!

« VS2005 项目名.vshost.exe Ajax 开发框架及评议 »

c#获取文件md5值

  • 本站大部分内容从网上收集,收集目的仅供研究、学习。涉及版权或不希望收录您的文章请您及时与我联系。
  • 本站IM群,请自行选择。请各位朋友按照自己喜好加入。加入群后请及时发言,防止被清理。谢谢您的合作!!!
  • QQ群:Y①WEB开发(ASP.NET)号码:7351660 QQ群:Y②WEB开发(ASP+.NET)号码:11864905
  • QQ群:Y③WEB开发(DIV+CSS)号码:16610506 QQ群:Y④WEB开发(JS+AJAX)号码:16143998
  • QQ群:Y⑤WEB开发(新手)号码:12777715 MSN群:yaosansi[at]126.com
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MyHash
{
        class md5
    {
        /// <summary>
        /// 实现对一个文件md5的读取,path为文件路径
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public string md5_hash(string path)
        {
            try
            {
                FileStream get_file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                System.Security.Cryptography.MD5CryptoServiceProvider get_md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                byte[] hash_byte = get_md5.ComputeHash(get_file);
                string resule = System.BitConverter.ToString(hash_byte);
                resule = resule.Replace("-", "");
                return resule;
            }
            catch (Exception e)
            {
               
                return e.ToString();
 
            }
         
          
 
        }
    }
}
 
 
 
 
 
 
===================================================
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
 
 
 public static void getFileMD5(string path)
        {
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] md5byte = md5.ComputeHash(fs);
            int i, j;
            foreach (byte b in md5byte)
            {
                i = Convert.ToInt32(b);
                j = i >> 4;
                Console.Write(Convert.ToString(j, 16));
                j = ((i << 4) & 0x00ff) >> 4;
                Console.Write(Convert.ToString(j, 16));
            }
            Console.ReadLine();

        }
 
 
 
 
 
 
 

原创文章如转载,请注明:转载自http://www.yaosansi.com
订阅本站,阅读更多文章

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog .Theme from Google黑板报 By Washun

Copyright 2005-2008 yaosansi'site All Rights Reserved.

感谢Denny·G 为本站提供FTP空间
辽ICP备05021434号

Search

  •  

赞助商广告

控制面板

最新评论及回复

最近发表