package com.fs.kingbos.util; import java.security.MessageDigest; import java.time.Instant; public class SignUtil { public static String sign(String data, String secret) { StringBuilder enValue = new StringBuilder(); enValue.append("kingbos"); enValue.append(secret); enValue.append(currentSeconds()); enValue.append("陕西金博"); enValue.append("zy01"); enValue.append(data); return encryptByMD5(enValue.toString()); } private static String encryptByMD5(String data) { StringBuilder sign = new StringBuilder(); try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] bytes = md.digest(data.getBytes("UTF-8")); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(bytes[i] & 0xFF); if (hex.length() == 1) { sign.append("0"); } sign.append(hex.toUpperCase()); } }catch (Exception e) { e.printStackTrace(); } return sign.toString(); } public static long currentSeconds(){ // 获取当前的秒级时间戳 return Instant.now().getEpochSecond(); } }