public class BinaryUtil
extends java.lang.Object
Constructor and Description |
---|
BinaryUtil() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
decodeBase64(java.lang.String data)
Decodes a Base64 string back to the original byte array.
|
static java.lang.String |
encodeBase64(byte[] data)
Encodes a byte array to a string with Base64 characters (websafe).
|
static java.lang.String |
encodeHexString(byte[] data)
Encodes a byte array to a string with hexadecimal numbers.
|
static byte[] |
hashBytes(java.lang.String alg,
byte[] data)
Performs a digest hash on the specified byte array.
|
static java.lang.String |
hashMD5(java.lang.String input)
Calculates the MD5 digest hash on the UTF-8 encoding of an input string.
|
static java.lang.String |
hashSHA256(java.lang.String input)
Calculates the SHA-256 digest hash on the UTF-8 encoding of an input
string.
|
public static java.lang.String hashMD5(java.lang.String input) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
input
- the input stringjava.security.NoSuchAlgorithmException
- if the MD5 algorithm isn't
available (should be RuntimeException)java.io.UnsupportedEncodingException
- if the UTF-8 encoding isn't
available (should be RuntimeException)public static java.lang.String hashSHA256(java.lang.String input) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
input
- the input stringjava.security.NoSuchAlgorithmException
- if the SHA-256 algorithm isn't
available (should be RuntimeException)java.io.UnsupportedEncodingException
- if the UTF-8 encoding isn't
available (should be RuntimeException)public static byte[] hashBytes(java.lang.String alg, byte[] data) throws java.security.NoSuchAlgorithmException
alg
- the hash algorithm (e.g. "MD5" or "SHA-256")data
- the data to hashjava.security.NoSuchAlgorithmException
- if the hash algorithm isn't availablepublic static java.lang.String encodeHexString(byte[] data)
data
- the byte arraypublic static java.lang.String encodeBase64(byte[] data)
data
- the byte arraypublic static byte[] decodeBase64(java.lang.String data)
data
- the Base64-encoded string