Question

how to implement calculate crc32 for data using dot net 3.5 api.I have done the same in java with following code.

   public static String getMAC (byte [] value) {  
    java.util.zip.CRC32 crc32 = new java.util.zip.CRC32 ();
    crc32.update(value);
    long newCRC = crc32.getValue();
    String crcString = Long.toHexString(newCRC);
    try {
        crcString = ISOUtil.padleft(Long.toHexString(newCRC), 8, '0');
    }
    catch (Exception e){
        e.printStackTrace();
    }

    if (ISOConstantsLibrary.DEBUG) System.out.println("for hex string: " + ISOUtil.hexString(value) + "\nmac" + crcString);        
    } 
Was it helpful?

Solution

The .NET FCL doesn't provide a class like java.util.zip.CRC32 so you have to roll your own. It's not tough, there's some decent examples out there:

Example 1 Example 2

OTHER TIPS

There is no standard CRC32 algorithm in .NET library. You can use other implementations like this. Also, if there are no specific requirements to use Crc32 (e.g. you just need to calculate checksum for checking integrity), I recommend to use Crc32C. This algorithm can be performed on modern CPUs, as result it usually 10x times faster than native implementation or 20x-60x times faster than any managed implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top