io.afu.utils.encryption.EncryptCommon Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils Show documentation
Show all versions of utils Show documentation
RffanLAB Utils For Many Way use
package io.afu.utils.encryption;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class EncryptCommon {
/**
* '将byte转换为16进制
* @param byteArray 需要转换的二进制
* @return String
*/
public static String byteArrayToHex(byte[] byteArray) {
// 首先初始化一个字符数组,用来存放每个16进制字符
char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
// new一个字符数组,这个就是用来组成结果字符串的(解释一下:一个byte是八位二进制,也就是2位十六进制字符(2的8次方等于16的2次方))
char[] resultCharArray = new char[byteArray.length * 2];
// 遍历字节数组,通过位运算(位运算效率高),转换成字符放到字符数组中去
int index = 0;
for (byte b : byteArray) {
resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
resultCharArray[index++] = hexDigits[b & 0xf];
}
// 字符数组组合成字符串返回
return new String(resultCharArray);
}
public static String formatSign(Map params,String seperater) {
String[] paramsKeys = params.keySet().toArray(new String[0]);
Arrays.sort(paramsKeys);
StringBuilder stringBuilder = new StringBuilder();
for (int i =0;i