Class HexCodec

java.lang.Object
cloud.opencode.base.crypto.codec.HexCodec

public final class HexCodec extends Object
Hexadecimal encoding and decoding utility - Convert between byte arrays and hex strings 十六进制编解码工具类 - 字节数组与十六进制字符串相互转换

Features | 主要功能:

  • Hexadecimal encoding and decoding - 十六进制编码和解码
  • Uppercase and lowercase support - 大小写支持

Usage Examples | 使用示例:

String hex = HexCodec.encode(bytes);
byte[] decoded = HexCodec.decode(hex);

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-crypto V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    Decode hexadecimal string to byte array (case-insensitive) 将十六进制字符串解码为字节数组(不区分大小写)
    static String
    encode(byte[] data)
    Encode byte array to lowercase hexadecimal string 将字节数组编码为小写十六进制字符串
    static String
    encodeUpperCase(byte[] data)
    Encode byte array to uppercase hexadecimal string 将字节数组编码为大写十六进制字符串
    static boolean
    Check if string is valid hexadecimal format 检查字符串是否为有效的十六进制格式

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • encode

      public static String encode(byte[] data)
      Encode byte array to lowercase hexadecimal string 将字节数组编码为小写十六进制字符串
      Parameters:
      data - byte array to encode
      Returns:
      lowercase hexadecimal string
      Throws:
      NullPointerException - if data is null
    • encodeUpperCase

      public static String encodeUpperCase(byte[] data)
      Encode byte array to uppercase hexadecimal string 将字节数组编码为大写十六进制字符串
      Parameters:
      data - byte array to encode
      Returns:
      uppercase hexadecimal string
      Throws:
      NullPointerException - if data is null
    • decode

      public static byte[] decode(String hex)
      Decode hexadecimal string to byte array (case-insensitive) 将十六进制字符串解码为字节数组(不区分大小写)
      Parameters:
      hex - hexadecimal string
      Returns:
      decoded byte array
      Throws:
      NullPointerException - if hex is null
      IllegalArgumentException - if hex is not valid hexadecimal
    • isValidHex

      public static boolean isValidHex(String hex)
      Check if string is valid hexadecimal format 检查字符串是否为有效的十六进制格式
      Parameters:
      hex - string to validate
      Returns:
      true if valid hexadecimal, false otherwise