惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
WordPress大学
WordPress大学
月光博客
月光博客
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - 司徒正美
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
Blog — PlanetScale
Blog — PlanetScale
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
L
LangChain Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
量子位

博客园 - magicdlf

[HIMCM暑期班]第4课: 扑克牌问题 [HIMCM暑期班]第3课:一个博弈问题 [HIMCM暑期班]第2课:建模 [HIMCM暑期班]第1课:概述 [C#]ASP.NET MVC 3 在线学习资料 [HIMCM]Consortium可以免费下载了! [C#]在Windows Service中使用ThreadPool [HIMCM]MathType小练习 [C#]DataGridView中使用数据绑定Enum类型 SRM 518 解题报告 SRM 522 解题报告 SRM 521 解题报告 [原创]简易版Socket聊天室 附源码 再谈C#扫雷 C#实现扫雷出炉 如何通过P/Invoke返回Struct和String Array zz .NET抽象工厂模式 from cnblogs 清空VSTFS cache 如何在VSTFS中设置email notification
计算文件的散列值
magicdlf · 2008-02-29 · via 博客园 - magicdlf

介绍一种使用md5计算hash值的方法。 下面的代码分别计算两个文件的散列值并比较两个文件是否相同。

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

        static bool fileCompare(string srcFilename, string destFilename)
        {
            try
            {
                //if file doesn't exist, will throw exception
                FileInfo srcFile = new FileInfo(srcFilename);
                FileInfo destFile = new FileInfo(destFilename);
                MD5 checksumCalculator = MD5.Create();
                byte[] srcChecksum = checksumCalculator.ComputeHash(srcFile.OpenRead());
                byte[] destChecksum = checksumCalculator.ComputeHash(destFile.OpenRead());
                if (srcChecksum.Length != destChecksum.Length)
                    return false;
                for (int index = 0; index < srcChecksum.Length; index++)
                {
                    if (srcChecksum[index] != destChecksum[index])
                        return false;
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return false;
        }