Class DigestUtil
MessageDigest
tasks.
This class is immutable and thread-safe.- Version:
- $Id: DigestUtils.java 1634433 2014-10-27 01:10:47Z ggregory $
-
Method Summary
Modifier and TypeMethodDescriptionstatic MessageDigest
Returns aMessageDigest
for the givenalgorithm
.static MessageDigest
Returns an MD2 MessageDigest.static MessageDigest
Returns an MD5 MessageDigest.static MessageDigest
Returns an SHA-1 digest.static MessageDigest
Returns an SHA-256 digest.static MessageDigest
Returns an SHA-384 digest.static MessageDigest
Returns an SHA-512 digest.static byte[]
md2
(byte[] data) Calculates the MD2 digest and returns the value as a 16 elementbyte[]
.static byte[]
md2
(InputStream data) Calculates the MD2 digest and returns the value as a 16 elementbyte[]
.static byte[]
Calculates the MD2 digest and returns the value as a 16 elementbyte[]
.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
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
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 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 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
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
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 abyte[]
.static byte[]
sha1
(InputStream data) Calculates the SHA-1 digest and returns the value as abyte[]
.static byte[]
Calculates the SHA-1 digest and returns the value as abyte[]
.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
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 abyte[]
.static byte[]
sha256
(InputStream data) Calculates the SHA-256 digest and returns the value as abyte[]
.static byte[]
Calculates the SHA-256 digest and returns the value as abyte[]
.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
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 abyte[]
.static byte[]
sha384
(InputStream data) Calculates the SHA-384 digest and returns the value as abyte[]
.static byte[]
Calculates the SHA-384 digest and returns the value as abyte[]
.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
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 abyte[]
.static byte[]
sha512
(InputStream data) Calculates the SHA-512 digest and returns the value as abyte[]
.static byte[]
Calculates the SHA-512 digest and returns the value as abyte[]
.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
Calculates the SHA-512 digest and returns the value as a hex string.
-
Method Details
-
getDigest
Returns aMessageDigest
for the givenalgorithm
.- Parameters:
algorithm
- the name of the algorithm requested. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard algorithm names.- Returns:
- A digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught.- See Also:
-
getMd2Digest
Returns an MD2 MessageDigest.- Returns:
- An MD2 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should never happen because MD2 is a built-in algorithm- Since:
- 1.7
- See Also:
-
DigestUtil.MessageDigestAlgorithms.MD2
-
getMd5Digest
Returns an MD5 MessageDigest.- Returns:
- An MD5 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should never happen because MD5 is a built-in algorithm- See Also:
-
DigestUtil.MessageDigestAlgorithms.MD5
-
getSha1Digest
Returns an SHA-1 digest.- Returns:
- An SHA-1 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should never happen because SHA-1 is a built-in algorithm- Since:
- 1.7
- See Also:
-
DigestUtil.MessageDigestAlgorithms.SHA_1
-
getSha256Digest
Returns an SHA-256 digest.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Returns:
- An SHA-256 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should never happen because SHA-256 is a built-in algorithm- See Also:
-
DigestUtil.MessageDigestAlgorithms.SHA_256
-
getSha384Digest
Returns an SHA-384 digest.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Returns:
- An SHA-384 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should never happen because SHA-384 is a built-in algorithm- See Also:
-
DigestUtil.MessageDigestAlgorithms.SHA_384
-
getSha512Digest
Returns an SHA-512 digest.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Returns:
- An SHA-512 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should never happen because SHA-512 is a built-in algorithm- See Also:
-
DigestUtil.MessageDigestAlgorithms.SHA_512
-
md2
public static byte[] md2(byte[] data) Calculates the MD2 digest and returns the value as a 16 elementbyte[]
.- Parameters:
data
- Data to digest- Returns:
- MD2 digest
- Since:
- 1.7
-
md2
Calculates the MD2 digest and returns the value as a 16 elementbyte[]
.- Parameters:
data
- Data to digest- Returns:
- MD2 digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
md2
Calculates the MD2 digest and returns the value as a 16 elementbyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStrings#getBytesUtf8(String)
- Returns:
- MD2 digest
- Since:
- 1.7
-
md2Hex
Calculates the MD2 digest and returns the value as a 32 character hex string.- Parameters:
data
- Data to digest- Returns:
- MD2 digest as a hex string
- Since:
- 1.7
-
md2Hex
Calculates the MD2 digest and returns the value as a 32 character hex string.- Parameters:
data
- Data to digest- Returns:
- MD2 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
md2Hex
Calculates the MD2 digest and returns the value as a 32 character hex string.- Parameters:
data
- Data to digest- Returns:
- MD2 digest as a hex string
- Since:
- 1.7
-
md2Base64
Calculates the MD2 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- MD2 digest as a hex string
- Since:
- 1.7
-
md2Base64
Calculates the MD2 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- MD2 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
md2Base64
Calculates the MD2 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- MD2 digest as a hex string
- Since:
- 1.7
-
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 to digest- Returns:
- MD5 digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.4
-
md5
Calculates the MD5 digest and returns the value as a 16 elementbyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStrings#getBytesUtf8(String)
- Returns:
- MD5 digest
-
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 to digest- Returns:
- MD5 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.4
-
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
-
md5Base64
Calculates the MD5 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- MD5 digest as a hex string
- Since:
- 1.7
-
md5Base64
Calculates the MD5 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- MD5 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
md5Base64
Calculates the MD5 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- MD5 digest as a hex string
- Since:
- 1.7
-
sha1
public static byte[] sha1(byte[] data) Calculates the SHA-1 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest
- Since:
- 1.7
-
sha1
Calculates the SHA-1 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
sha1
Calculates the SHA-1 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStrings#getBytesUtf8(String)
- Returns:
- SHA-1 digest
-
sha1Hex
Calculates the SHA-1 digest and returns the value as a hex string.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest as a hex string
- Since:
- 1.7
-
sha1Hex
Calculates the SHA-1 digest and returns the value as a hex string.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
sha1Hex
Calculates the SHA-1 digest and returns the value as a hex string.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest as a hex string
- Since:
- 1.7
-
sha1Base64
Calculates the SHA-1 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest as a hex string
- Since:
- 1.7
-
sha1Base64
Calculates the SHA-1 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
sha1Base64
Calculates the SHA-1 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest as a hex string
- Since:
- 1.7
-
sha256
public static byte[] sha256(byte[] data) Calculates the SHA-256 digest and returns the value as abyte[]
.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest
- Since:
- 1.4
-
sha256
Calculates the SHA-256 digest and returns the value as abyte[]
.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.4
-
sha256
Calculates the SHA-256 digest and returns the value as abyte[]
.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest; converted to bytes usingStrings#getBytesUtf8(String)
- Returns:
- SHA-256 digest
- Since:
- 1.4
-
sha256Hex
Calculates the SHA-256 digest and returns the value as a hex string.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest as a hex string
- Since:
- 1.4
-
sha256Hex
Calculates the SHA-256 digest and returns the value as a hex string.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.4
-
sha256Hex
Calculates the SHA-256 digest and returns the value as a hex string.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest as a hex string
- Since:
- 1.4
-
sha256Base64
Calculates the SHA-256 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest as a hex string
- Since:
- 1.7
-
sha256Base64
Calculates the SHA-256 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
sha256Base64
Calculates the SHA-256 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest as a hex string
- Since:
- 1.7
-
sha384
public static byte[] sha384(byte[] data) Calculates the SHA-384 digest and returns the value as abyte[]
.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-384 digest
- Since:
- 1.4
-
sha384
Calculates the SHA-384 digest and returns the value as abyte[]
.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-384 digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.4
-
sha384
Calculates the SHA-384 digest and returns the value as abyte[]
.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest; converted to bytes usingStrings#getBytesUtf8(String)
- Returns:
- SHA-384 digest
- Since:
- 1.4
-
sha384Hex
Calculates the SHA-384 digest and returns the value as a hex string.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-384 digest as a hex string
- Since:
- 1.4
-
sha384Hex
Calculates the SHA-384 digest and returns the value as a hex string.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-384 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.4
-
sha384Hex
Calculates the SHA-384 digest and returns the value as a hex string.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-384 digest as a hex string
- Since:
- 1.4
-
sha384Base64
Calculates the SHA-384 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-384 digest as a hex string
- Since:
- 1.7
-
sha384Base64
Calculates the SHA-384 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-384 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
sha384Base64
Calculates the SHA-384 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-384 digest as a hex string
- Since:
- 1.7
-
sha512
public static byte[] sha512(byte[] data) Calculates the SHA-512 digest and returns the value as abyte[]
.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-512 digest
- Since:
- 1.4
-
sha512
Calculates the SHA-512 digest and returns the value as abyte[]
.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-512 digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.4
-
sha512
Calculates the SHA-512 digest and returns the value as abyte[]
.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest; converted to bytes usingStrings#getBytesUtf8(String)
- Returns:
- SHA-512 digest
- Since:
- 1.4
-
sha512Hex
Calculates the SHA-512 digest and returns the value as a hex string.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-512 digest as a hex string
- Since:
- 1.4
-
sha512Hex
Calculates the SHA-512 digest and returns the value as a hex string.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-512 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.4
-
sha512Hex
Calculates the SHA-512 digest and returns the value as a hex string.Throws a
RuntimeException
on JRE versions prior to 1.4.0.- Parameters:
data
- Data to digest- Returns:
- SHA-512 digest as a hex string
- Since:
- 1.4
-
sha512Base64
Calculates the SHA-512 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-512 digest as a hex string
- Since:
- 1.7
-
sha512Base64
Calculates the SHA-512 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-512 digest as a hex string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.7
-
sha512Base64
Calculates the SHA-512 digest and returns the value as a base64 encoded string.- Parameters:
data
- Data to digest- Returns:
- SHA-512 digest as a hex string
- Since:
- 1.7
-