c# CRC32 库的使用

// 引用 

using System.IO.Hashing;

 

string file_path = openFileDialog1.FileName;
text_main.AppendText("BOOT文件路径:" + file_path + ".\n");

FileStream h_file = new FileStream(file_path, FileMode.Open, FileAccess.Read, FileShare.Read);

// 获取文件长度
int len = (int)h_file.Length;

// 创建数组 用于保存文件
byte[] file_array = new byte[len];

// 将文件保存到数组里
h_file.Read(file_array, 0, len);

// 关闭文件
h_file.Close();

 

// 进行 CRC32 计算
UInt32 crc32_value = Crc32.HashToUInt32(file_array);

 

text_main.AppendText("BOOT文件 CRC32:0x" + crc32_value.ToString("X") + " .\n");

 

运算结果 :

BOOT文件 CRC32:0xD4FD9219 .

posted on 2026-01-27 13:40  所长  阅读(0)  评论(0)    收藏  举报

导航