package com.sandu.ximon.admin.manager.iot.rrpc.util;
|
|
import cn.hutool.core.util.HexUtil;
|
|
import java.util.zip.CRC32;
|
|
/**
|
* @author chenjiantian
|
* @date 2021/12/3 18:43
|
*/
|
public class CRC32Utils {
|
public static String getCRC32(String hex) {
|
CRC32 crc32 = new CRC32();
|
byte[] bytes = HexUtil.decodeHex(hex);
|
crc32.update(bytes);
|
long value = crc32.getValue();
|
return SupplementUtils.suppleZero(Long.toHexString(value).toUpperCase(),8);
|
}
|
|
public static boolean validateFrame(String frame, String crc32) {
|
String crc32Validate = getCRC32(frame);
|
if(crc32.equals(crc32Validate)){
|
return true;
|
}
|
return false;
|
}
|
}
|