|
@@ -2,6 +2,7 @@ package cn.efunbox.audio.utils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.codec.binary.Hex;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
@@ -21,6 +22,13 @@ public class Encrypt {
|
|
|
|
|
|
public static final String SIGN = "sign";
|
|
|
|
|
|
+ private static Base64 base64;
|
|
|
+
|
|
|
+ static {
|
|
|
+ base64 = new Base64();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static String createSHA256Sign(Map<String, String> paramMap, String signKey) {
|
|
|
|
|
|
List<String> sortedKeys = new ArrayList<String>();
|
|
@@ -164,36 +172,23 @@ public class Encrypt {
|
|
|
|
|
|
byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));
|
|
|
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
+ String encodeSign = base64.encodeToString(array);
|
|
|
|
|
|
- for (byte item : array) {
|
|
|
-
|
|
|
- sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return sb.toString().toUpperCase();
|
|
|
+ return encodeSign;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
+
|
|
|
+ //idChannel=100103&idDevice=10.31.49.16&ts=159559185715
|
|
|
Map<String,String> param = new HashMap<>();
|
|
|
- param.put("idChannel","1000");
|
|
|
- param.put("idDevice","test");
|
|
|
- param.put("ts",System.currentTimeMillis() / 1000 + "");
|
|
|
- System.out.println(JSONObject.toJSONString(param));
|
|
|
-// String sign = Encrypt.createHMACSHA256(param,"IhOTiTyMLDNNLFuP");
|
|
|
- String sign = Encrypt.createHMACSHA256(param,"AzaSB2RR0boUz1WQ");
|
|
|
+ param.put("idChannel","100103");
|
|
|
+ param.put("idDevice","10.31.49.16");
|
|
|
+ param.put("x-ts","159559185715");
|
|
|
+ log.info(JSONObject.toJSONString(param));
|
|
|
+ String sign = Encrypt.createHMACSHA256(param,"IhOTiTyMLDNNLFuP");
|
|
|
log.info(sign);
|
|
|
|
|
|
- String encode = Base64.getEncoder().encodeToString(sign.getBytes(StandardCharsets.UTF_8));
|
|
|
-
|
|
|
- log.info(encode);
|
|
|
-
|
|
|
- String decode = new String(Base64.getDecoder().decode(encode), StandardCharsets.UTF_8);
|
|
|
- log.info(decode);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|