Game Development Reference
Crc32 crc = new Crc32();
byte result = crc.Calculate(stream);
Using the data “This is a test” will result in a 32-bit checksum value of 2042881507.
The result will be a 32-bit (4-octet) checksum of the data that was provided to the
CRC-32 algorithm, and will subsequently be compared against a future checksum
There is one potential problem with the CRC-32 Checksum algorithm in regards
to malicious security attacks. Generally, these issues are not important for verifi-
cation of simple data integrity, but it may be advisable to seek an alternative algo-
rithm in environments where security is a concern; verifying the integrity of pack-
ets in a multiplayer environment, for example.
The problem with the CRC-32 (Cyclic Redundancy Checksum) algorithm is that
it is not collision-proof, meaning that it is possible to generate two checksum val-
ues that are identical. This is not an extremely common occurrence, but it intro-
duces enough exploitability that a malicious plain-text attack could be used to
spoof an integrity check. The probability that two different blocks of data will have
the same checksum value in an N-bit checksum is 1/2 N . The larger the value rep-
resented by N, the lower the probability that two different blocks of data will have
the same checksum value. So the probability that our CRC-32 implementation will
generate an identical checksum for two different blocks of data is 1/2 32 ,a percent-
age that is reasonable enough for most situations.
As an alternative, you can utilize the built-in MD5 algorithm from the
System.Security.Cryptography namespace. This algorithm is known so far to be
collision-proof, and may be used in place of CRC-32 for better security and cred-
ibility with a bit of increased overhead.
Implementing the built-in functionality from Microsoft is very easy. Reference the
System.Security.Cryptography namespace and use the following code:
byte data = new byte[DATA_SIZE];
MD5 md5 = new MD5CryptoServiceProvider();
byte result = md5.ComputeHash(data);