Package org.zkoss.zk.ui.sys
Class DigestUtilsHelper
java.lang.Object
org.zkoss.zk.ui.sys.DigestUtilsHelper
A helper class for class DigestUtils for md5 encoding, internal use only.
The following implementation for md5 encoding is referred from
https://commons.apache.org/proper/commons-codec/archives/1.8/index.html
- Since:
- 8.0.2
- Author:
- wenning
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decodeHex(char[] data) Converts an array of characters representing hexadecimal values into an array of bytes of those same values.static byte[]decodeHexString(String data) Converts a String into an array of bytes.static char[]encodeHex(byte[] data) Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.static char[]encodeHex(byte[] data, boolean toLowerCase) Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.protected static char[]encodeHex(byte[] data, char[] toDigits) Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.static StringencodeHexString(byte[] data) Converts an array of bytes into a String representing the hexadecimal values of each byte in order.static byte[]getBytesUtf8(String string) Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.static MessageDigestReturns aMessageDigestfor the givenalgorithm.static MessageDigestReturns an MD5 MessageDigest.static byte[]md5(byte[] data) Calculates the MD5 digest and returns the value as a 16 elementbyte[].static byte[]md5(InputStream data) Calculates the MD5 digest and returns the value as a 16 elementbyte[].static byte[]Calculates the MD5 digest and returns the value as a 16 elementbyte[].static Stringmd5Hex(InputStream data) Calculates the MD5 digest and returns the value as a 32 character hex string.static StringCalculates the MD5 digest and returns the value as a 32 character hex string.protected static inttoDigit(char ch, int index) Converts a hexadecimal character to an integer.
-
Constructor Details
-
DigestUtilsHelper
public DigestUtilsHelper()
-
-
Method Details
-
md5Hex
Calculates the MD5 digest and returns the value as a 32 character hex string.- Parameters:
data- data to digest- Returns:
- MD5 digest as a hex string
-
md5Hex
Calculates the MD5 digest and returns the value as a 32 character hex string.- Parameters:
data- data stream to digest (will not be closed)- Returns:
- MD5 digest as a hex string
- Throws:
IOException
-
md5
Calculates the MD5 digest and returns the value as a 16 elementbyte[].- Parameters:
data- data to digest- Returns:
- MD5 digest
-
md5
public static byte[] md5(byte[] data) Calculates the MD5 digest and returns the value as a 16 elementbyte[].- Parameters:
data- data to digest- Returns:
- MD5 digest
-
md5
Calculates the MD5 digest and returns the value as a 16 elementbyte[].- Parameters:
data- data stream to digest (will not be closed)- Returns:
- MD5 digest
- Throws:
IOException
-
getMd5Digest
Returns an MD5 MessageDigest.- Returns:
- An MD5 digest instance.
-
getDigest
Returns aMessageDigestfor the givenalgorithm.- Parameters:
algorithm-- Returns:
- An MD5 digest instance.
- Throws:
IllegalArgumentException
-
getBytesUtf8
Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.- Parameters:
string- the String to encode, may benull- Returns:
- encoded bytes, or
nullif the input string wasnull
-
encodeHexString
Converts an array of bytes into a String representing the hexadecimal values of each byte in order. The returned String will be double the length of the passed array, as it takes two characters to represent any given byte.- Parameters:
data- a byte[] to convert to Hex characters- Returns:
- A String containing hexadecimal characters
-
encodeHex
public static char[] encodeHex(byte[] data) Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. The returned array will be double the length of the passed array, as it takes two characters to represent any given byte.- Parameters:
data- a byte[] to convert to Hex characters- Returns:
- A char[] containing hexadecimal characters
-
encodeHex
public static char[] encodeHex(byte[] data, boolean toLowerCase) Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. The returned array will be double the length of the passed array, as it takes two characters to represent any given byte.- Parameters:
data- a byte[] to convert to Hex characterstoLowerCase-trueconverts to lowercase,falseto uppercase- Returns:
- A char[] containing hexadecimal characters
-
encodeHex
protected static char[] encodeHex(byte[] data, char[] toDigits) Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. The returned array will be double the length of the passed array, as it takes two characters to represent any given byte.- Parameters:
data- a byte[] to convert to Hex characterstoDigits- the output alphabet- Returns:
- A char[] containing hexadecimal characters
-
decodeHexString
Converts a String into an array of bytes.- Parameters:
data- a byte[] to convert to Hex characters- Returns:
- A String containing hexadecimal characters
- Throws:
IllegalArgumentException
-
decodeHex
Converts an array of characters representing hexadecimal values into an array of bytes of those same values. The returned array will be half the length of the passed array, as it takes two characters to represent any given byte. An exception is thrown if the passed char array has an odd number of elements.- Parameters:
data- An array of characters containing hexadecimal digits- Returns:
- A byte array containing binary data decoded from the supplied char array.
- Throws:
IllegalArgumentException
-
toDigit
Converts a hexadecimal character to an integer.- Parameters:
ch- A character to convert to an integer digitindex- The index of the character in the source- Returns:
- An integer
- Throws:
IllegalArgumentException
-