计算字节数组的 CRC32

Compute CRC32 of a Byte Array

在 C# 中,我正在努力 generate/compute CRC32。目前我正在使用这种方法: (crc32 class 是从 this source 导入的)

Crc32 c = new Crc32();
var hash = string.Empty;
foreach(byte b in c.ComputeHash(package))
{
    hash += b.ToString("0x").ToLower();
}

然后:

Console.WriteLine(hash);

结果是:0048284b

但我想以十六进制形式获取它。像“0xD754C033”这样我可以把它放在一个字节数组中。 对字节数组的 CRC32 计算进行了一些挖掘,但找不到任何可行的方法。

长话短说:如何计算字节数组的 CRC32 十六进制? (正确)

P.S:根据 link 提供的答案不重复。

我找到了一个非常适合我的问题的解决方案。万一它发生在任何人身上,我将发布我当前的解决问题的方法。也许不是最好的,但出于测试目的,它可以完成工作。

byte[] package= {255,13,45,56};
//The byte array that will be used to calculate CRC32C hex

foreach (byte b in package)
{
Console.WriteLine("0x{0:X}", b);
//Writing the elements in hex format to provide visibility (for testing)
//Take note that "0x{0:X}" part is used for hex formatting of a string. X can be changed depending on the context eg. x2, x8 etc.
}
Console.WriteLine("-");//Divider
/* Actual solution part */                
String crc = String.Format("0x{0:X}", Crc32CAlgorithm.Compute(package));
/* Actual solution part */ 
Console.WriteLine(crc);
/* Output: 0x6627634B */
/*Using CRC32.NET NuGet package for Crc32CAlgorithm class. 
Then calling Compute method statically and passing byte array to the method. Keep in mind it returns uint type value. Then writing the returned variable in hex format as described earlier. */

提到的 Nuget 包:Crc32.NET