小编use*_*039的帖子

为什么我的SHA-1函数在C#中为这两个文件显示相同的输出?

我能够显示所选的两个不同文件的两个不同的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)

c# hash md5 cryptography

4
推荐指数
2
解决办法
73
查看次数

标签 统计

c# ×1

cryptography ×1

hash ×1

md5 ×1