wjc
2026-03-25 4c6f5510f545f27ab7a5b76fbc40278f118ffe6b
app/src/main/java/com/hdl/photovoltaic/utils/ByteUtils.java
@@ -11,16 +11,9 @@
import java.util.Arrays;
import java.util.List;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/**
 * Created by Tong on 2021/9/23.
 */
public class ByteUtils {
    public static byte[] toByteArray(List<Byte> list) {
@@ -208,6 +201,28 @@
        return i;
    }
    /**
     * 字节数组转十六进制字符串
     *
     * @param bytes 字节数组
     * @return 十六进制字符串
     */
    public static String bytesToHexString(byte[] bytes) {
        if (bytes == null || bytes.length == 0) {
            return "";
        }
        StringBuilder sb = new StringBuilder(bytes.length * 2);
        for (byte b : bytes) {
            // 将 byte 转为无符号的 int(0-255)
            int unsignedByte = b & 0xff;
            // 转为十六进制,不足两位补 0
            if (unsignedByte < 0x10) {
                sb.append("0");
            }
            sb.append(Integer.toHexString(unsignedByte));
        }
        return sb.toString().toUpperCase(); // 或 toLowerCase()
    }
}