C#类模块crc32加密算法

C/C++ 2020-08-30 11:02:45

C#类模块crc32加密算法

另分享两个自己封装的模块
时间模块:时间对比,是否在两段时间内,时间差值,时间戳
加密模块:aes des 3des md5 sha bytes到hex hex到bytes
///


/// crc32加密
///

///被加密的字节集
/// 成功返回结果,失败返回0
public uint GetCRC32(byte[] bytes)
{
try
{
uint crcs = 0;
uint byteslen = (uint)bytes.Length;
uint[] crcTable = new uint[256];
if (byteslen <= 0) { return 0; }
for (int i = 0; i < 256; i++)
{
crcs = (uint)i;
//Debug.WriteLine(crcs + " | " + (crcs & 1) + " | " + i);
for (int d = 0; d < 8; d++)
{
if ((crcs & 1) != 0)
{
crcs = (((crcs >> 1) & 0x7FFFFFFF) ^ 0xEDB88320);
}
else
{
crcs = ((crcs >> 1) & 0x7FFFFFFF);
}

}
crcTable = crcs;
}
uint crc = 0xFFFFFFFF;
for (uint i = 0; i < byteslen; i++)
{
uint wz = ((uint)bytes ^ (crc & 255));
crc = ((crc >> 8) & 0xFFFFFF) ^ crcTable[wz];
}
return ~crc;
}
catch (Exception err)
{
Debug.WriteLine("crc32加密出错 fail;error :" + err.ToString());
return 0;
}
}