修改md5方法

jieling
DESKTOP-C3M45P4\dengdan 2025-02-19 15:51:46 +08:00
parent be334c1c5b
commit bd2e6a1847
2 changed files with 34 additions and 1 deletions

View File

@ -129,7 +129,7 @@ public class UserInfoController {
return resp.toString();
}
String signStr = api_key + appota_user_id + server_id + GamotaConstats.secretKey;
String sign = MD5Util.encrypByMd5(signStr);
String sign = MD5Util.encrypByMd5New(signStr);
if(!sign.equals(signature)){
LOGGER.info("sign=" + sign + " --- signature="+signature);
resp.put("message", "signature error");
@ -337,4 +337,13 @@ public class UserInfoController {
return "GodLvInfo";
}
public static void main(String args[]){
String api_key = GamotaConstats.apikey;
String appota_user_id = "2618078";
String server_id = "10157";
String signStr = api_key + appota_user_id + server_id + GamotaConstats.secretKey;
String sign = MD5Util.encrypByMd5New(signStr);
System.out.println(sign);
}
}

View File

@ -30,4 +30,28 @@ public class MD5Util {
}
return "";
}
public static String encrypByMd5New(String context) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(context.getBytes());//update处理
byte [] encryContext = md.digest();//调用该方法完成计算
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < encryContext.length; offset++) {//做相应的转化(十六进制)
i = encryContext[offset];
if (i < 0) i += 256;
if (i < 16) buf.append("0");
buf.append(Integer.toHexString(i));
}
return buf.toString().toLowerCase();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
}