Class HexCodec
java.lang.Object
cloud.opencode.base.crypto.codec.HexCodec
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 TypeMethodDescriptionstatic byte[]Decode hexadecimal string to byte array (case-insensitive) 将十六进制字符串解码为字节数组(不区分大小写)static Stringencode(byte[] data) Encode byte array to lowercase hexadecimal string 将字节数组编码为小写十六进制字符串static StringencodeUpperCase(byte[] data) Encode byte array to uppercase hexadecimal string 将字节数组编码为大写十六进制字符串static booleanisValidHex(String hex) Check if string is valid hexadecimal format 检查字符串是否为有效的十六进制格式
-
Method Details
-
encode
Encode byte array to lowercase hexadecimal string 将字节数组编码为小写十六进制字符串- Parameters:
data- byte array to encode- Returns:
- lowercase hexadecimal string
- Throws:
NullPointerException- if data is null
-
encodeUpperCase
Encode byte array to uppercase hexadecimal string 将字节数组编码为大写十六进制字符串- Parameters:
data- byte array to encode- Returns:
- uppercase hexadecimal string
- Throws:
NullPointerException- if data is null
-
decode
Decode hexadecimal string to byte array (case-insensitive) 将十六进制字符串解码为字节数组(不区分大小写)- Parameters:
hex- hexadecimal string- Returns:
- decoded byte array
- Throws:
NullPointerException- if hex is nullIllegalArgumentException- if hex is not valid hexadecimal
-
isValidHex
Check if string is valid hexadecimal format 检查字符串是否为有效的十六进制格式- Parameters:
hex- string to validate- Returns:
- true if valid hexadecimal, false otherwise
-