1.引入using System.IO;
2.变量:
private XmlParser m_xmlFile;
private static UInt32 Crcval = 0xE0D5E91E;
2.CRC校验:
public String GetFileCRC32(String filePath)
{
//filePath需要检验的文档的路径
const uint polynomial = 0xEDB88320;
uint[] table = new uint[256];
for (uint i = 0; i < 256; i++)
{
uint crc = i;
for (uint j = 8; j > 0; j--)
{
if ((crc & 1) == 1)
crc = (crc >> 1) ^ polynomial;
else
crc >>= 1;
}
table[i] = crc;
}
UInt32 crcValue = 0xFFFFFFFF;
var bytes = File.ReadAllBytes(filePath);
foreach (byte b in bytes)
{
byte tableIndex = (byte)((crcValue & 0xFF) ^ b);
crcValue = (crcValue >> 8) ^ table[tableIndex];
}
crcValue = ~crcValue;
return crcValue.ToString();
}