开发者

.net 3.5:how to implement calculate crc32 for data using dot net 3.5 api?

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 [] v开发者_Python百科alue) {  
    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);        
    } 


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜