A端执行getToken方法把TokenA和data传给B端,B端接收到A端的TokenA和data后,执行本地方法getToken获得TokenB,
比较TokenA和TokenB,相等则校验成功,getToken方法如下:
public static String getToken(String data){
//key为密钥
private String key = "74c2d6cf-a9f0-4278-8cd8-b1ab11a5c79e";
String dataAndKey = data +"|"+ key;
String resultString = "";
try {
resultString = new String(dataAndKey);
MessageDigest md = MessageDigest.getInstance("MD5");
resultString = byteArrayToHexString(md.digest(resultString
.getBytes("UTF-8")));
} catch (Exception exception) {
}
return resultString;
}
最后推荐一个比较成熟的spring cloud 架构,欢迎大家收藏 https://gitee.com/gitsc/pro-cloud