我能够显示所选的两个不同文件的两个不同的MD5值,但是,SHA-1函数显示两者的完全相同的值.这是为什么?
我不是一个优秀的程序员,所以我不知道这个代码是否特别好,但任何帮助或建议将不胜感激.
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
FileStream file1 = new FileStream(lblBrowse1.Text, FileMode.Open);
FileStream file2 = new FileStream(lblBrowse2.Text, FileMode.Open);
byte[] hash1 = md5.ComputeHash(file1);
byte[] hash2 = md5.ComputeHash(file2);
byte[] hash3 = sha1.ComputeHash(file1);
byte[] hash4 = sha1.ComputeHash(file2);
file1.Close();
file2.Close();
textBox1.Text = BitConverter.ToString(hash1).Replace("-", "");
textBox2.Text = BitConverter.ToString(hash2).Replace("-", "");
textBox6.Text = BitConverter.ToString(hash3).Replace("-", "");
textBox7.Text = BitConverter.ToString(hash4).Replace("-", "");
if (textBox1.Text == textBox2.Text)
{
MessageBox.Show("These two files are identical.");
}
else
{
MessageBox.Show("These two files are different.");
}
Run Code Online (Sandbox Code Playgroud)