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 hexadecimal values into an
array of bytes of those same values.
|
static byte[] |
decode(char[] data)
Converts an array of characters representing hexadecimal values into an
array of bytes of those same values.
|
static byte[] |
decode(String hex)
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 hexadecimal values of each byte in order.
|
static String |
encodeToString(byte[] bytes)
Encodes the specified 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 Hex()
public static String encodeToString(byte[] bytes)
bytes
- the byte array to Hex-encode.public static char[] encode(byte[] data)
data
- byte[] to convert to Hex characterspublic static byte[] decode(byte[] array) throws IllegalArgumentException
array
- An array of character bytes containing hexadecimal digitsIllegalArgumentException
- Thrown if an odd number of characters is supplied
to this functiondecode(char[])
public static byte[] decode(String hex)
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 hexadecimal digitsIllegalArgumentException
- if an odd number or illegal of characters
is suppliedprotected static int toDigit(char ch, int index) throws IllegalArgumentException
ch
- A character to convert to an integer digitindex
- The index of the character in the sourceIllegalArgumentException
- if ch is an illegal hex characterCopyright © 2004–2020 The Apache Software Foundation. All rights reserved.