A easy to use Cyclic Redundancy Check(CRC) package
$ dotnet add package w3.CRCRecommended for data with less than 256B
The CRC calculation is as follows:
byte[] data = BitConverter.GetBytes("Hello, world!"); // Input data - byte array
uint crc = CRC8.ComputeChecksum(data);
Along with the data validation:
using var stream = File.OpenRead("testFile.bin"); // Input data - also a byte array
bool isValid = CRC8.Validate(dataWithCRC);
The CRC32Stream is different as it uses streams as inputs instead of byte arrays to save memory space when calculating the CRC. The calculation is as follows:
var crcStream = new CRC32Stream(inputStream);
uint crc = crcStream.ComputeChecksum(8192, 0, (int)crcStream.Length);
And for the validation:
var crcStream = new CRC32Stream(inputStream);
bool isValid = crcStream.Validate(8192, 0, (int)crcStream.Length);