1
zj
2025-08-18 8b5ed9e9ff4400ad5638bab870e52af4f90d101a
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.nq.utils;
 
import java.security.MessageDigest;
 
public class SignAPI {
 
 
        /**
         * MD5加密
         * @param signSource
         * @return
         */
        private static String calculate(String signSource) {
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(signSource.getBytes("utf-8"));
                byte[] b = md.digest();
 
                StringBuffer buf = new StringBuffer("");
                for (int offset = 0; offset < b.length; offset++) {
                    int i = b[offset];
                    if (i < 0)
                        i += 256;
                    if (i < 16)
                        buf.append("0");
                    buf.append(Integer.toHexString(i));
                }
 
                return buf.toString();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
 
    public static String sign(String signSource, String key) {
        if (org.apache.commons.lang.StringUtils.isNotBlank(key)) {
            signSource = signSource + "&key=" + key;
        }
        return calculate(signSource);
    }
 
    public static boolean validateSignByKey(String signSource, String key, String retsign) {
        if (org.apache.commons.lang.StringUtils.isNotBlank(key)) {
            signSource = signSource + "&key=" + key;
        }
        String signkey = calculate(signSource);
        System.out.println("signkey======" + signkey);
        if (signkey.equals(retsign)) {
            return true;
        }
        return false;
    }
 
}