2021与蓝度共同重构项目,服务端
chenjiantian
2021-12-06 295411fed71f1ea1286316ccc395d28cc5743fa8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;
    }
}