public final class DigestUtil extends Object
MessageDigest tasks.
This class is immutable and thread-safe.| Modifier and Type | Method and Description |
|---|---|
static MessageDigest |
getDigest(String algorithm)
Returns a
MessageDigest for the given algorithm. |
static MessageDigest |
getMd2Digest()
Returns an MD2 MessageDigest.
|
static MessageDigest |
getMd5Digest()
Returns an MD5 MessageDigest.
|
static MessageDigest |
getSha1Digest()
Returns an SHA-1 digest.
|
static MessageDigest |
getSha256Digest()
Returns an SHA-256 digest.
|
static MessageDigest |
getSha384Digest()
Returns an SHA-384 digest.
|
static MessageDigest |
getSha512Digest()
Returns an SHA-512 digest.
|
static byte[] |
md2(byte[] data)
Calculates the MD2 digest and returns the value as a 16 element
byte[]. |
static byte[] |
md2(InputStream data)
Calculates the MD2 digest and returns the value as a 16 element
byte[]. |
static byte[] |
md2(String data)
Calculates the MD2 digest and returns the value as a 16 element
byte[]. |
static String |
md2Base64(byte[] data)
Calculates the MD2 digest and returns the value as a base64 encoded string.
|
static String |
md2Base64(InputStream data)
Calculates the MD2 digest and returns the value as a base64 encoded string.
|
static String |
md2Base64(String data)
Calculates the MD2 digest and returns the value as a base64 encoded string.
|
static String |
md2Hex(byte[] data)
Calculates the MD2 digest and returns the value as a 32 character hex string.
|
static String |
md2Hex(InputStream data)
Calculates the MD2 digest and returns the value as a 32 character hex string.
|
static String |
md2Hex(String data)
Calculates the MD2 digest and returns the value as a 32 character hex string.
|
static byte[] |
md5(byte[] data)
Calculates the MD5 digest and returns the value as a 16 element
byte[]. |
static byte[] |
md5(InputStream data)
Calculates the MD5 digest and returns the value as a 16 element
byte[]. |
static byte[] |
md5(String data)
Calculates the MD5 digest and returns the value as a 16 element
byte[]. |
static String |
md5Base64(byte[] data)
Calculates the MD5 digest and returns the value as a base64 encoded string.
|
static String |
md5Base64(InputStream data)
Calculates the MD5 digest and returns the value as a base64 encoded string.
|
static String |
md5Base64(String data)
Calculates the MD5 digest and returns the value as a base64 encoded string.
|
static String |
md5Hex(byte[] data)
Calculates the MD5 digest and returns the value as a 32 character hex string.
|
static String |
md5Hex(InputStream data)
Calculates the MD5 digest and returns the value as a 32 character hex string.
|
static String |
md5Hex(String data)
Calculates the MD5 digest and returns the value as a 32 character hex string.
|
static byte[] |
sha1(byte[] data)
Calculates the SHA-1 digest and returns the value as a
byte[]. |
static byte[] |
sha1(InputStream data)
Calculates the SHA-1 digest and returns the value as a
byte[]. |
static byte[] |
sha1(String data)
Calculates the SHA-1 digest and returns the value as a
byte[]. |
static String |
sha1Base64(byte[] data)
Calculates the SHA-1 digest and returns the value as a base64 encoded string.
|
static String |
sha1Base64(InputStream data)
Calculates the SHA-1 digest and returns the value as a base64 encoded string.
|
static String |
sha1Base64(String data)
Calculates the SHA-1 digest and returns the value as a base64 encoded string.
|
static String |
sha1Hex(byte[] data)
Calculates the SHA-1 digest and returns the value as a hex string.
|
static String |
sha1Hex(InputStream data)
Calculates the SHA-1 digest and returns the value as a hex string.
|
static String |
sha1Hex(String data)
Calculates the SHA-1 digest and returns the value as a hex string.
|
static byte[] |
sha256(byte[] data)
Calculates the SHA-256 digest and returns the value as a
byte[]. |
static byte[] |
sha256(InputStream data)
Calculates the SHA-256 digest and returns the value as a
byte[]. |
static byte[] |
sha256(String data)
Calculates the SHA-256 digest and returns the value as a
byte[]. |
static String |
sha256Base64(byte[] data)
Calculates the SHA-256 digest and returns the value as a base64 encoded string.
|
static String |
sha256Base64(InputStream data)
Calculates the SHA-256 digest and returns the value as a base64 encoded string.
|
static String |
sha256Base64(String data)
Calculates the SHA-256 digest and returns the value as a base64 encoded string.
|
static String |
sha256Hex(byte[] data)
Calculates the SHA-256 digest and returns the value as a hex string.
|
static String |
sha256Hex(InputStream data)
Calculates the SHA-256 digest and returns the value as a hex string.
|
static String |
sha256Hex(String data)
Calculates the SHA-256 digest and returns the value as a hex string.
|
static byte[] |
sha384(byte[] data)
Calculates the SHA-384 digest and returns the value as a
byte[]. |
static byte[] |
sha384(InputStream data)
Calculates the SHA-384 digest and returns the value as a
byte[]. |
static byte[] |
sha384(String data)
Calculates the SHA-384 digest and returns the value as a
byte[]. |
static String |
sha384Base64(byte[] data)
Calculates the SHA-384 digest and returns the value as a base64 encoded string.
|
static String |
sha384Base64(InputStream data)
Calculates the SHA-384 digest and returns the value as a base64 encoded string.
|
static String |
sha384Base64(String data)
Calculates the SHA-384 digest and returns the value as a base64 encoded string.
|
static String |
sha384Hex(byte[] data)
Calculates the SHA-384 digest and returns the value as a hex string.
|
static String |
sha384Hex(InputStream data)
Calculates the SHA-384 digest and returns the value as a hex string.
|
static String |
sha384Hex(String data)
Calculates the SHA-384 digest and returns the value as a hex string.
|
static byte[] |
sha512(byte[] data)
Calculates the SHA-512 digest and returns the value as a
byte[]. |
static byte[] |
sha512(InputStream data)
Calculates the SHA-512 digest and returns the value as a
byte[]. |
static byte[] |
sha512(String data)
Calculates the SHA-512 digest and returns the value as a
byte[]. |
static String |
sha512Base64(byte[] data)
Calculates the SHA-512 digest and returns the value as a base64 encoded string.
|
static String |
sha512Base64(InputStream data)
Calculates the SHA-512 digest and returns the value as a base64 encoded string.
|
static String |
sha512Base64(String data)
Calculates the SHA-512 digest and returns the value as a base64 encoded string.
|
static String |
sha512Hex(byte[] data)
Calculates the SHA-512 digest and returns the value as a hex string.
|
static String |
sha512Hex(InputStream data)
Calculates the SHA-512 digest and returns the value as a hex string.
|
static String |
sha512Hex(String data)
Calculates the SHA-512 digest and returns the value as a hex string.
|
public static MessageDigest getDigest(String algorithm)
MessageDigest for the given algorithm.
the name of the algorithm requested. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard
algorithm names.IllegalArgumentException - when a NoSuchAlgorithmException is caught.MessageDigest.getInstance(String)public static MessageDigest getMd2Digest()
IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because MD2 is a
built-in algorithmMessageDigestAlgorithms#MD2public static MessageDigest getMd5Digest()
IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because MD5 is a
built-in algorithmMessageDigestAlgorithms#MD5public static MessageDigest getSha1Digest()
IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-1 is a
built-in algorithmMessageDigestAlgorithms#SHA_1public static MessageDigest getSha256Digest()
Throws a RuntimeException on JRE versions prior to 1.4.0.
IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-256 is a
built-in algorithmMessageDigestAlgorithms#SHA_256public static MessageDigest getSha384Digest()
Throws a RuntimeException on JRE versions prior to 1.4.0.
IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-384 is a
built-in algorithmMessageDigestAlgorithms#SHA_384public static MessageDigest getSha512Digest()
Throws a RuntimeException on JRE versions prior to 1.4.0.
IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-512 is a
built-in algorithmMessageDigestAlgorithms#SHA_512public static byte[] md2(byte[] data)
byte[].data - Data to digestpublic static byte[] md2(InputStream data) throws IOException
byte[].data - Data to digestIOException - On error reading from the streampublic static byte[] md2(String data)
byte[].data - Data to digest; converted to bytes using StringUtils#getBytesUtf8(String)public static String md2Hex(byte[] data)
data - Data to digestpublic static String md2Hex(InputStream data) throws IOException
data - Data to digestIOException - On error reading from the streampublic static String md2Hex(String data)
data - Data to digestpublic static String md2Base64(byte[] data)
data - Data to digestpublic static String md2Base64(InputStream data) throws IOException
data - Data to digestIOException - On error reading from the streampublic static String md2Base64(String data)
data - Data to digestpublic static byte[] md5(byte[] data)
byte[].data - Data to digestpublic static byte[] md5(InputStream data) throws IOException
byte[].data - Data to digestIOException - On error reading from the streampublic static byte[] md5(String data)
byte[].data - Data to digest; converted to bytes using StringUtils#getBytesUtf8(String)public static String md5Hex(byte[] data)
data - Data to digestpublic static String md5Hex(InputStream data) throws IOException
data - Data to digestIOException - On error reading from the streampublic static String md5Hex(String data)
data - Data to digestpublic static String md5Base64(byte[] data)
data - Data to digestpublic static String md5Base64(InputStream data) throws IOException
data - Data to digestIOException - On error reading from the streampublic static String md5Base64(String data)
data - Data to digestpublic static byte[] sha1(byte[] data)
byte[].data - Data to digestpublic static byte[] sha1(InputStream data) throws IOException
byte[].data - Data to digestIOException - On error reading from the streampublic static byte[] sha1(String data)
byte[].data - Data to digest; converted to bytes using StringUtils#getBytesUtf8(String)public static String sha1Hex(byte[] data)
data - Data to digestpublic static String sha1Hex(InputStream data) throws IOException
data - Data to digestIOException - On error reading from the streampublic static String sha1Hex(String data)
data - Data to digestpublic static String sha1Base64(byte[] data)
data - Data to digestpublic static String sha1Base64(InputStream data) throws IOException
data - Data to digestIOException - On error reading from the streampublic static String sha1Base64(String data)
data - Data to digestpublic static byte[] sha256(byte[] data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static byte[] sha256(InputStream data) throws IOException
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestIOException - On error reading from the streampublic static byte[] sha256(String data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digest; converted to bytes using StringUtils#getBytesUtf8(String)public static String sha256Hex(byte[] data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static String sha256Hex(InputStream data) throws IOException
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestIOException - On error reading from the streampublic static String sha256Hex(String data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static String sha256Base64(byte[] data)
data - Data to digestpublic static String sha256Base64(InputStream data) throws IOException
data - Data to digestIOException - On error reading from the streampublic static String sha256Base64(String data)
data - Data to digestpublic static byte[] sha384(byte[] data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static byte[] sha384(InputStream data) throws IOException
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestIOException - On error reading from the streampublic static byte[] sha384(String data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digest; converted to bytes using StringUtils#getBytesUtf8(String)public static String sha384Hex(byte[] data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static String sha384Hex(InputStream data) throws IOException
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestIOException - On error reading from the streampublic static String sha384Hex(String data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static String sha384Base64(byte[] data)
data - Data to digestpublic static String sha384Base64(InputStream data) throws IOException
data - Data to digestIOException - On error reading from the streampublic static String sha384Base64(String data)
data - Data to digestpublic static byte[] sha512(byte[] data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static byte[] sha512(InputStream data) throws IOException
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestIOException - On error reading from the streampublic static byte[] sha512(String data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digest; converted to bytes using StringUtils#getBytesUtf8(String)public static String sha512Hex(byte[] data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static String sha512Hex(InputStream data) throws IOException
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestIOException - On error reading from the streampublic static String sha512Hex(String data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static String sha512Base64(byte[] data)
data - Data to digestpublic static String sha512Base64(InputStream data) throws IOException
data - Data to digestIOException - On error reading from the streamCopyright © 2021. All rights reserved.