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

推荐订阅源

U
Unit 42
Help Net Security
Help Net Security
The Hacker News
The Hacker News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
A
Arctic Wolf
T
Tor Project blog
Jina AI
Jina AI
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
Security Latest
Security Latest
Latest news
Latest news
Last Week in AI
Last Week in AI
博客园 - 司徒正美
P
Privacy International News Feed
T
Tenable Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
腾讯CDC
博客园 - 聂微东
Scott Helme
Scott Helme
爱范儿
爱范儿
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
I
Intezer
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LINUX DO - 热门话题
有赞技术团队
有赞技术团队
S
Secure Thoughts
WordPress大学
WordPress大学
The Cloudflare Blog
AWS News Blog
AWS News Blog
B
Blog RSS Feed
Cyberwarzone
Cyberwarzone
S
Security Affairs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Register - Security
The Register - Security
L
LINUX DO - 最新话题
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
T
Troy Hunt's Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Securelist
S
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - davidullua

Google chrome的离线安装版 百度进军B2C行业 No size set for variable length data type: String Response.WriteFile()下载文件,打开对话框出现两次 - davidullua - 博客园 to create table if table do not exist -- to backup and restore table in oracle Gmail邀请 to call Session_End() event when user closed Browser When Session_End() and Session_Start() Fires about Ora-03114 disable asp.net connection pool(pooling) Oracle FAQ: 未在本地计算机上注册"OraOLEDB.Oracle"提供程序 (The 'OraOLEDB.Oracle' provider is not registered on the local machine) solution - davidullua ora-00054 , alter system kill session 'id,serial#' Change Path of C:\Documents and Settings - davidullua About FormsAuthentication.RedirectFromLoginPage(string username, bool createPersistentCookie) Send email by jmail or CDO according to configuration C#中调用控件的事件 [导入]C#向Sql Server中插入记录时单引号的处理 [导入]C#使用CDO发送邮件 [导入]使用jmail组件发送电子邮件(C#) [导入]C#中使用反射显示程序集的所有类型和属性 [导入]使用Oracle Developer Tools For Visual Studio .NET
File Comparer - To compare two files and check whether they have the same content
davidullua · 2005-10-19 · via 博客园 - davidullua

Since it is slow and has low performance to compare to files byte by byte, we could use MD5 algorithm to computer the Hash Code of the FileStream for specified files to check whether two files have the same content. .Net has MD5 algorithm inside, you can search MD5 in MSDN for detail.  You can download the full sample code and compiled program: https://files.cnblogs.com/davidullua/FileComparer.zip

Here's the sample code to compute hash code of a file:

        /// <summary>
        
/// to computer HashCode of a File, different files will generate different HashCode
        
/// </summary>
        
/// <param name="fileName"></param>
        
/// <returns></returns>

        public static string ComputeHashCode(string fileName)
        
{
            
if(!File.Exists(fileName))
            
{
                
throw new FileNotFoundException("File does not exist",fileName);
            }
            

            Stream fileStream 
= File.OpenRead(fileName); 
            
try 
            
{                
                MD5CryptoServiceProvider MD5Alg 
= new MD5CryptoServiceProvider(); 

                
byte[] hashValue = MD5Alg.ComputeHash(fileStream); 

                
return BitConverter.ToString(hashValue);                 
            }
 

            
catch 
            

                
throw
            }
 
            
finally 
            

                fileStream.Close();
            }
     
        }

Here's the code to compare two files' HashCode:

        /// <summary>
        
/// used to Compare Two files' HashCode, return true or false
        
/// </summary>
        
/// <param name="fileOne"></param>
        
/// <param name="fileTwo"></param>
        
/// <returns></returns>

        public static bool CompareFiles(string fileOne, string fileTwo) 
        
{
            
if(!File.Exists(fileOne) || !File.Exists(fileTwo))
            
{
                
throw new FileNotFoundException("File does not exist");
            }


            
try 
            
{  
                
string stringValue1 = ComputeHashCode(fileOne); 
                
string stringValue2 = ComputeHashCode(fileTwo);  

                
return (stringValue1.Equals(stringValue2)); 
            }
 

            
catch 
            

                
throw
            }
 


        }