All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.afu.utils.encryption.EncryptCommon Maven / Gradle / Ivy

There is a newer version: 0.0.55-RELEASE
Show newest version
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
            


© 2015 - 2024 Weber Informatics LLC | Privacy Policy