public class Hex extends Object
560660) with modifications to enable Hex conversion without a full dependency on Commons Codec. We didn't want to reinvent the wheel of great work they've done, but also didn't want to force every Shiro user to depend on the commons-codec.jar
As per the Apache 2.0 license, the original copyright notice and all author and copyright information have remained in tact.
| Constructor and Description |
|---|
Hex()
|
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
decode(byte[] array)
Converts an array of character bytes representing hexidecimal values into an array of bytes of those same values.
|
static byte[] |
decode(char[] data)
Converts an array of characters representing hexidecimal values into an array of bytes of those same values.
|
static byte[] |
decode(String
Converts the specified Hex-encoded String into a raw byte array.
|
static char[] |
encode(byte[] data)
Converts an array of bytes into an array of characters representing the hexidecimal values of each byte in order.
|
static String |
encodeToString(byte[] bytes)
Encodes the specifed byte array to a character array and then returns that character array as a String.
|
protected static int |
toDigit(char ch, int index)
Converts a hexadecimal character to an integer.
|
public static StringencodeToString(byte[] bytes)
bytes - the byte array to Hex-encode.
public static char[] encode(byte[] data)
data - byte[] to convert to Hex characters
public static byte[] decode(byte[] array)
throws IllegalArgumentException
array - An array of character bytes containing hexidecimal digits
IllegalArgumentException - Thrown if an odd number of characters is supplied to this function
decode(char[])
public static byte[] decode(Stringhex)
decode(char[]) using the argument's hex.toCharArray() value.
hex - a Hex-encoded String.
public static byte[] decode(char[] data)
throws IllegalArgumentException
data - An array of characters containing hexidecimal digits
IllegalArgumentException - if an odd number or illegal of characters is supplied
protected static int toDigit(char ch,
int index)
throws IllegalArgumentException
ch - A character to convert to an integer digit
index - The index of the character in the source
IllegalArgumentException - if ch is an illegal hex character