Calculating checksums are perhaps not the first thing you would think of needing to do in PowerShell. But if you ever are in a situation that you need to calculate a checksum using the CRC32 algorithm, I got you covered with this small function.
I can’t take full credit for the code itself, all I did was converting the code from C to PowerShell.
Example
[System.Text.Encoding]::ASCII.GetBytes("PowerShell") | Get-CRC32
This will give you the CRC32 checksum of 2730794414, which is an INT64. If you want to convert it to HEX, you can do the following:
[System.Convert]::ToString(2730794414,16)
This will give you the HEX value of a2c49dae.
The function takes a byte array as input, which is the reason I had to convert the string in the example above.
Here is the function it self, with another example included:
This seems to generate crc32B and not crc32.
LikeLiked by 1 person
No zeros at the beginning of hex CRC, you need to add them manually.
LikeLike