Package org.apache.commons.codec.digest
Class DigestUtils
java.lang.Object
org.apache.commons.codec.digest.DigestUtils
Operations to simplify common 
MessageDigest tasks. This class is immutable and thread-safe. However the MessageDigest instances it
 creates generally won't be.
 
 The MessageDigestAlgorithms class provides constants for standard digest algorithms that can be used with the getDigest(String) method and
 other methods that require the Digest algorithm name.
 
Note: The class has shorthand methods for all the algorithms present as standard in Java 6. This approach requires lots of methods for each algorithm, and quickly becomes unwieldy. The following code works with all algorithms:
 import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA_224;
 ...
 byte [] digest = new DigestUtils(SHA_224).digest(dataToDigest);
 String hdigest = new DigestUtils(SHA_224).digestAsHex(new File("pom.xml"));
 - See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionDeprecated.since 1.11; only useful to preserve binary compatibilityDigestUtils(String name) Creates an instance using the providedMessageDigestparameter.DigestUtils(MessageDigest digest) Creates an instance using the providedMessageDigestparameter.
- 
Method SummaryModifier and TypeMethodDescriptionbyte[]digest(byte[] data) Reads through a byte array and returns the digest for the data.byte[]Reads through a File and returns the digest for the databyte[]digest(InputStream data) Reads through an InputStream and returns the digest for the databyte[]Reads through a byte array and returns the digest for the data.byte[]digest(ByteBuffer data) Reads through a ByteBuffer and returns the digest for the databyte[]digest(Path data, OpenOption... options) Reads through a File and returns the digest for the datastatic byte[]digest(MessageDigest messageDigest, byte[] data) Reads through a byte array and returns the digest for the data.static byte[]digest(MessageDigest messageDigest, File data) Reads through a File and returns the digest for the datastatic byte[]digest(MessageDigest messageDigest, InputStream data) Reads through an InputStream and returns the digest for the datastatic byte[]digest(MessageDigest messageDigest, RandomAccessFile data) Reads through a RandomAccessFile using non-blocking-io (NIO) and returns the digest for the datastatic byte[]digest(MessageDigest messageDigest, ByteBuffer data) Reads through a ByteBuffer and returns the digest for the datastatic byte[]digest(MessageDigest messageDigest, Path data, OpenOption... options) Reads through a File and returns the digest for the datadigestAsHex(byte[] data) Reads through a byte array and returns the digest for the data.digestAsHex(File data) Reads through a File and returns the digest for the datadigestAsHex(InputStream data) Reads through an InputStream and returns the digest for the datadigestAsHex(String data) Reads through a byte array and returns the digest for the data.digestAsHex(ByteBuffer data) Reads through a ByteBuffer and returns the digest for the datadigestAsHex(Path data, OpenOption... options) Reads through a File and returns the digest for the datastatic MessageDigestGets aMessageDigestfor the givenalgorithm.static MessageDigestgetDigest(String algorithm, MessageDigest defaultMessageDigest) Gets aMessageDigestfor the givenalgorithmor a default if there is a problem getting the algorithm.static MessageDigestGets an MD2 MessageDigest.static MessageDigestGets an MD5 MessageDigest.Returns the message digest instance.static MessageDigestGets an SHA-1 digest.static MessageDigestGets an SHA-256 digest.static MessageDigestGets an SHA3-224 digest.static MessageDigestReturns an SHA3-256 digest.static MessageDigestGets an SHA3-384 digest.static MessageDigestGets an SHA3-512 digest.static MessageDigestGets an SHA-384 digest.static MessageDigestGets an SHA-512/224 digest.static MessageDigestGets an SHA-512/256 digest.static MessageDigestGets an SHA-512 digest.static MessageDigestDeprecated.(1.11) UsegetSha1Digest()static booleanisAvailable(String messageDigestAlgorithm) Test whether the algorithm is supported.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 Stringmd2Hex(byte[] data) Calculates the MD2 digest and returns the value as a 32 character hexadecimal string.static Stringmd2Hex(InputStream data) Calculates the MD2 digest and returns the value as a 32 character hexadecimal string.static StringCalculates the MD2 digest and returns the value as a 32 character hexadecimal 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 Stringmd5Hex(byte[] data) Calculates the MD5 digest and returns the value as a 32 character hexadecimal string.static Stringmd5Hex(InputStream data) Calculates the MD5 digest and returns the value as a 32 character hexadecimal string.static StringCalculates the MD5 digest and returns the value as a 32 character hexadecimal string.static byte[]sha(byte[] data) Deprecated.(1.11) Usesha1(byte[])static byte[]sha(InputStream data) Deprecated.(1.11) Usesha1(InputStream)static byte[]Deprecated.(1.11) Usesha1(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 Stringsha1Hex(byte[] data) Calculates the SHA-1 digest and returns the value as a hexadecimal string.static Stringsha1Hex(InputStream data) Calculates the SHA-1 digest and returns the value as a hexadecimal string.static StringCalculates the SHA-1 digest and returns the value as a hexadecimal 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 Stringsha256Hex(byte[] data) Calculates the SHA-256 digest and returns the value as a hexadecimal string.static Stringsha256Hex(InputStream data) Calculates the SHA-256 digest and returns the value as a hexadecimal string.static StringCalculates the SHA-256 digest and returns the value as a hexadecimal string.static byte[]sha3_224(byte[] data) Calculates the SHA3-224 digest and returns the value as abyte[].static byte[]sha3_224(InputStream data) Calculates the SHA3-224 digest and returns the value as abyte[].static byte[]Calculates the SHA3-224 digest and returns the value as abyte[].static Stringsha3_224Hex(byte[] data) Calculates the SHA3-224 digest and returns the value as a hexadecimal string.static Stringsha3_224Hex(InputStream data) Calculates the SHA3-224 digest and returns the value as a hexadecimal string.static Stringsha3_224Hex(String data) Calculates the SHA3-224 digest and returns the value as a hexadecimal string.static byte[]sha3_256(byte[] data) Calculates the SHA3-256 digest and returns the value as abyte[].static byte[]sha3_256(InputStream data) Calculates the SHA3-256 digest and returns the value as abyte[].static byte[]Calculates the SHA3-256 digest and returns the value as abyte[].static Stringsha3_256Hex(byte[] data) Calculates the SHA3-256 digest and returns the value as a hexadecimal string.static Stringsha3_256Hex(InputStream data) Calculates the SHA3-256 digest and returns the value as a hexadecimal string.static Stringsha3_256Hex(String data) Calculates the SHA3-256 digest and returns the value as a hexadecimal string.static byte[]sha3_384(byte[] data) Calculates the SHA3-384 digest and returns the value as abyte[].static byte[]sha3_384(InputStream data) Calculates the SHA3-384 digest and returns the value as abyte[].static byte[]Calculates the SHA3-384 digest and returns the value as abyte[].static Stringsha3_384Hex(byte[] data) Calculates the SHA3-384 digest and returns the value as a hexadecimal string.static Stringsha3_384Hex(InputStream data) Calculates the SHA3-384 digest and returns the value as a hexadecimal string.static Stringsha3_384Hex(String data) Calculates the SHA3-384 digest and returns the value as a hexadecimal string.static byte[]sha3_512(byte[] data) Calculates the SHA3-512 digest and returns the value as abyte[].static byte[]sha3_512(InputStream data) Calculates the SHA3-512 digest and returns the value as abyte[].static byte[]Calculates the SHA3-512 digest and returns the value as abyte[].static Stringsha3_512Hex(byte[] data) Calculates the SHA3-512 digest and returns the value as a hexadecimal string.static Stringsha3_512Hex(InputStream data) Calculates the SHA3-512 digest and returns the value as a hexadecimal string.static Stringsha3_512Hex(String data) Calculates the SHA3-512 digest and returns the value as a hexadecimal 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 Stringsha384Hex(byte[] data) Calculates the SHA-384 digest and returns the value as a hexadecimal string.static Stringsha384Hex(InputStream data) Calculates the SHA-384 digest and returns the value as a hexadecimal string.static StringCalculates the SHA-384 digest and returns the value as a hexadecimal 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 byte[]sha512_224(byte[] data) Calculates the SHA-512/224 digest and returns the value as abyte[].static byte[]sha512_224(InputStream data) Calculates the SHA-512/224 digest and returns the value as abyte[].static byte[]sha512_224(String data) Calculates the SHA-512/224 digest and returns the value as abyte[].static Stringsha512_224Hex(byte[] data) Calculates the SHA-512/224 digest and returns the value as a hexadecimal string.static Stringsha512_224Hex(InputStream data) Calculates the SHA-512/224 digest and returns the value as a hexadecimal string.static Stringsha512_224Hex(String data) Calculates the SHA-512/224 digest and returns the value as a hexadecimal string.static byte[]sha512_256(byte[] data) Calculates the SHA-512/256 digest and returns the value as abyte[].static byte[]sha512_256(InputStream data) Calculates the SHA-512/256 digest and returns the value as abyte[].static byte[]sha512_256(String data) Calculates the SHA-512/256 digest and returns the value as abyte[].static Stringsha512_256Hex(byte[] data) Calculates the SHA-512/256 digest and returns the value as a hexadecimal string.static Stringsha512_256Hex(InputStream data) Calculates the SHA-512/256 digest and returns the value as a hexadecimal string.static Stringsha512_256Hex(String data) Calculates the SHA-512/256 digest and returns the value as a hexadecimal string.static Stringsha512Hex(byte[] data) Calculates the SHA-512 digest and returns the value as a hexadecimal string.static Stringsha512Hex(InputStream data) Calculates the SHA-512 digest and returns the value as a hexadecimal string.static StringCalculates the SHA-512 digest and returns the value as a hexadecimal string.static StringshaHex(byte[] data) Deprecated.(1.11) Usesha1Hex(byte[])static StringshaHex(InputStream data) Deprecated.(1.11) Usesha1Hex(InputStream)static StringDeprecated.(1.11) Usesha1Hex(String)static MessageDigestupdateDigest(MessageDigest messageDigest, byte[] valueToDigest) Updates the givenMessageDigest.static MessageDigestupdateDigest(MessageDigest digest, File data) Reads through a File and updates the digest for the datastatic MessageDigestupdateDigest(MessageDigest digest, InputStream inputStream) Reads through an InputStream and updates the digest for the datastatic MessageDigestupdateDigest(MessageDigest digest, RandomAccessFile data) Reads through a RandomAccessFile and updates the digest for the data using non-blocking-io (NIO)static MessageDigestupdateDigest(MessageDigest messageDigest, String valueToDigest) Updates the givenMessageDigestfrom a String (converted to bytes using UTF-8).static MessageDigestupdateDigest(MessageDigest messageDigest, ByteBuffer valueToDigest) Updates the givenMessageDigest.static MessageDigestupdateDigest(MessageDigest digest, Path path, OpenOption... options) Reads through a Path and updates the digest for the data
- 
Constructor Details- 
DigestUtilsDeprecated.since 1.11; only useful to preserve binary compatibilityPreserves binary compatibility only. As for previous versions does not provide useful behavior
- 
DigestUtilsCreates an instance using the providedMessageDigestparameter. This can then be used to create digests using methods such asdigest(byte[])anddigestAsHex(File).- Parameters:
- digest- the- MessageDigestto use
- Since:
- 1.11
 
- 
DigestUtilsCreates an instance using the providedMessageDigestparameter. This can then be used to create digests using methods such asdigest(byte[])anddigestAsHex(File).- Parameters:
- name- the name of the- MessageDigestto use
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
- Since:
- 1.11
- See Also:
 
 
- 
- 
Method Details- 
digestReads through a byte array and returns the digest for the data. Provided for symmetry with other methods.- Parameters:
- messageDigest- The MessageDigest to use (for example MD5)
- data- Data to digest
- Returns:
- the digest
- Since:
- 1.11
 
- 
digestReads through a ByteBuffer and returns the digest for the data- Parameters:
- messageDigest- The MessageDigest to use (for example MD5)
- data- Data to digest
- Returns:
- the digest
- Since:
- 1.11
 
- 
digestReads through a File and returns the digest for the data- Parameters:
- messageDigest- The MessageDigest to use (for example MD5)
- data- Data to digest
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.11
 
- 
digestReads through an InputStream and returns the digest for the data- Parameters:
- messageDigest- The MessageDigest to use (for example MD5)
- data- Data to digest
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.11 (was private)
 
- 
digestpublic static byte[] digest(MessageDigest messageDigest, Path data, OpenOption... options) throws IOException Reads through a File and returns the digest for the data- Parameters:
- messageDigest- The MessageDigest to use (for example MD5)
- data- Data to digest
- options- options How to open the file
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.14
 
- 
digestReads through a RandomAccessFile using non-blocking-io (NIO) and returns the digest for the data- Parameters:
- messageDigest- The MessageDigest to use (for example MD5)
- data- Data to digest
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.14
 
- 
getDigestGets aMessageDigestfor 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 a- NoSuchAlgorithmExceptionis caught.
- See Also:
 
- 
getDigestGets aMessageDigestfor the givenalgorithmor a default if there is a problem getting the algorithm.- Parameters:
- algorithm- the name of the algorithm requested. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard algorithm names.
- defaultMessageDigest- The default MessageDigest.
- Returns:
- A digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
- Since:
- 1.11
- See Also:
 
- 
getMd2DigestGets an MD2 MessageDigest.- Returns:
- An MD2 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should never happen because MD2 is a built-in algorithm
- Since:
- 1.7
- See Also:
 
- 
getMd5DigestGets an MD5 MessageDigest.- Returns:
- An MD5 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should never happen because MD5 is a built-in algorithm
- See Also:
 
- 
getSha1DigestGets an SHA-1 digest.- Returns:
- An SHA-1 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should never happen because SHA-1 is a built-in algorithm
- Since:
- 1.7
- See Also:
 
- 
getSha256DigestGets an SHA-256 digest.- Returns:
- An SHA-256 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should never happen because SHA-256 is a built-in algorithm
- See Also:
 
- 
getSha3_224DigestGets an SHA3-224 digest.- Returns:
- An SHA3-224 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should not happen on Oracle Java 9 and greater.
- Since:
- 1.12
- See Also:
 
- 
getSha3_256DigestReturns an SHA3-256 digest.- Returns:
- An SHA3-256 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should not happen on Oracle Java 9 and greater.
- Since:
- 1.12
- See Also:
 
- 
getSha3_384DigestGets an SHA3-384 digest.- Returns:
- An SHA3-384 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should not happen on Oracle Java 9 and greater.
- Since:
- 1.12
- See Also:
 
- 
getSha3_512DigestGets an SHA3-512 digest.- Returns:
- An SHA3-512 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should not happen on Oracle Java 9 and greater.
- Since:
- 1.12
- See Also:
 
- 
getSha384DigestGets an SHA-384 digest.- Returns:
- An SHA-384 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should never happen because SHA-384 is a built-in algorithm
- See Also:
 
- 
getSha512_224DigestGets an SHA-512/224 digest.- Returns:
- An SHA-512/224 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
- See Also:
 
- 
getSha512_256DigestGets an SHA-512/256 digest.- Returns:
- An SHA-512/256 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
- See Also:
 
- 
getSha512DigestGets an SHA-512 digest.- Returns:
- An SHA-512 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught, which should never happen because SHA-512 is a built-in algorithm
- See Also:
 
- 
getShaDigestDeprecated.(1.11) UsegetSha1Digest()Gets an SHA-1 digest.- Returns:
- An SHA-1 digest instance.
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught
 
- 
isAvailableTest whether the algorithm is supported.- Parameters:
- messageDigestAlgorithm- the algorithm name
- Returns:
- trueif the algorithm can be found
- Since:
- 1.11
 
- 
md2Calculates the MD2 digest and returns the value as a 16 elementbyte[].- Parameters:
- data- Data to digest
- Returns:
- MD2 digest
- Since:
- 1.7
 
- 
md2Calculates 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
 
- 
md2Calculates the MD2 digest and returns the value as a 16 elementbyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- MD2 digest
- Since:
- 1.7
 
- 
md2HexCalculates the MD2 digest and returns the value as a 32 character hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- MD2 digest as a hexadecimal string
- Since:
- 1.7
 
- 
md2HexCalculates the MD2 digest and returns the value as a 32 character hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- MD2 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.7
 
- 
md2HexCalculates the MD2 digest and returns the value as a 32 character hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- MD2 digest as a hexadecimal string
- Since:
- 1.7
 
- 
md5Calculates the MD5 digest and returns the value as a 16 elementbyte[].- Parameters:
- data- Data to digest
- Returns:
- MD5 digest
 
- 
md5Calculates 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
 
- 
md5Calculates the MD5 digest and returns the value as a 16 elementbyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- MD5 digest
 
- 
md5HexCalculates the MD5 digest and returns the value as a 32 character hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- MD5 digest as a hexadecimal string
 
- 
md5HexCalculates the MD5 digest and returns the value as a 32 character hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- MD5 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.4
 
- 
md5HexCalculates the MD5 digest and returns the value as a 32 character hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- MD5 digest as a hexadecimal string
 
- 
shaDeprecated.(1.11) Usesha1(byte[])Calculates the SHA-1 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-1 digest
 
- 
shaDeprecated.(1.11) Usesha1(InputStream)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.4
 
- 
shaDeprecated.(1.11) Usesha1(String)Calculates the SHA-1 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-1 digest
 
- 
sha1Calculates the SHA-1 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-1 digest
- Since:
- 1.7
 
- 
sha1Calculates 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
 
- 
sha1Calculates the SHA-1 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA-1 digest
 
- 
sha1HexCalculates the SHA-1 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-1 digest as a hexadecimal string
- Since:
- 1.7
 
- 
sha1HexCalculates the SHA-1 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-1 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.7
 
- 
sha1HexCalculates the SHA-1 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-1 digest as a hexadecimal string
- Since:
- 1.7
 
- 
sha256Calculates the SHA-256 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-256 digest
- Since:
- 1.4
 
- 
sha256Calculates the SHA-256 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-256 digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.4
 
- 
sha256Calculates the SHA-256 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA-256 digest
- Since:
- 1.4
 
- 
sha256HexCalculates the SHA-256 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-256 digest as a hexadecimal string
- Since:
- 1.4
 
- 
sha256HexCalculates the SHA-256 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-256 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.4
 
- 
sha256HexCalculates the SHA-256 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-256 digest as a hexadecimal string
- Since:
- 1.4
 
- 
sha3_224Calculates the SHA3-224 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA3-224 digest
- Since:
- 1.12
 
- 
sha3_224Calculates the SHA3-224 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA3-224 digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.12
 
- 
sha3_224Calculates the SHA3-224 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA3-224 digest
- Since:
- 1.12
 
- 
sha3_224HexCalculates the SHA3-224 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-224 digest as a hexadecimal string
- Since:
- 1.12
 
- 
sha3_224HexCalculates the SHA3-224 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-224 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.12
 
- 
sha3_224HexCalculates the SHA3-224 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-224 digest as a hexadecimal string
- Since:
- 1.12
 
- 
sha3_256Calculates the SHA3-256 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA3-256 digest
- Since:
- 1.12
 
- 
sha3_256Calculates the SHA3-256 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA3-256 digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.12
 
- 
sha3_256Calculates the SHA3-256 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA3-256 digest
- Since:
- 1.12
 
- 
sha3_256HexCalculates the SHA3-256 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-256 digest as a hexadecimal string
- Since:
- 1.12
 
- 
sha3_256HexCalculates the SHA3-256 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-256 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.12
 
- 
sha3_256HexCalculates the SHA3-256 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-256 digest as a hexadecimal string
- Since:
- 1.12
 
- 
sha3_384Calculates the SHA3-384 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA3-384 digest
- Since:
- 1.12
 
- 
sha3_384Calculates the SHA3-384 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA3-384 digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.12
 
- 
sha3_384Calculates the SHA3-384 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA3-384 digest
- Since:
- 1.12
 
- 
sha3_384HexCalculates the SHA3-384 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-384 digest as a hexadecimal string
- Since:
- 1.12
 
- 
sha3_384HexCalculates the SHA3-384 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-384 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.12
 
- 
sha3_384HexCalculates the SHA3-384 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-384 digest as a hexadecimal string
- Since:
- 1.12
 
- 
sha3_512Calculates the SHA3-512 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA3-512 digest
- Since:
- 1.12
 
- 
sha3_512Calculates the SHA3-512 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA3-512 digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.12
 
- 
sha3_512Calculates the SHA3-512 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA3-512 digest
- Since:
- 1.12
 
- 
sha3_512HexCalculates the SHA3-512 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-512 digest as a hexadecimal string
- Since:
- 1.12
 
- 
sha3_512HexCalculates the SHA3-512 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-512 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.12
 
- 
sha3_512HexCalculates the SHA3-512 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA3-512 digest as a hexadecimal string
- Since:
- 1.12
 
- 
sha384Calculates the SHA-384 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-384 digest
- Since:
- 1.4
 
- 
sha384Calculates the SHA-384 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-384 digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.4
 
- 
sha384Calculates the SHA-384 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA-384 digest
- Since:
- 1.4
 
- 
sha384HexCalculates the SHA-384 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-384 digest as a hexadecimal string
- Since:
- 1.4
 
- 
sha384HexCalculates the SHA-384 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-384 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.4
 
- 
sha384HexCalculates the SHA-384 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-384 digest as a hexadecimal string
- Since:
- 1.4
 
- 
sha512Calculates the SHA-512 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-512 digest
- Since:
- 1.4
 
- 
sha512Calculates the SHA-512 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-512 digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.4
 
- 
sha512Calculates the SHA-512 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA-512 digest
- Since:
- 1.4
 
- 
sha512_224Calculates the SHA-512/224 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-512/224 digest
- Since:
- 1.14
 
- 
sha512_224Calculates the SHA-512/224 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-512/224 digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.14
 
- 
sha512_224Calculates the SHA-512/224 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA-512/224 digest
- Since:
- 1.14
 
- 
sha512_224HexCalculates the SHA-512/224 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-512/224 digest as a hexadecimal string
- Since:
- 1.14
 
- 
sha512_224HexCalculates the SHA-512/224 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-512/224 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.14
 
- 
sha512_224HexCalculates the SHA-512/224 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-512/224 digest as a hexadecimal string
- Since:
- 1.14
 
- 
sha512_256Calculates the SHA-512/256 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-512/256 digest
- Since:
- 1.14
 
- 
sha512_256Calculates the SHA-512/256 digest and returns the value as abyte[].- Parameters:
- data- Data to digest
- Returns:
- SHA-512/256 digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.14
 
- 
sha512_256Calculates the SHA-512/256 digest and returns the value as abyte[].- Parameters:
- data- Data to digest; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- SHA-512/224 digest
- Since:
- 1.14
 
- 
sha512_256HexCalculates the SHA-512/256 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-512/256 digest as a hexadecimal string
- Since:
- 1.14
 
- 
sha512_256HexCalculates the SHA-512/256 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-512/256 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.14
 
- 
sha512_256HexCalculates the SHA-512/256 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-512/256 digest as a hexadecimal string
- Since:
- 1.14
 
- 
sha512HexCalculates the SHA-512 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-512 digest as a hexadecimal string
- Since:
- 1.4
 
- 
sha512HexCalculates the SHA-512 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-512 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.4
 
- 
sha512HexCalculates the SHA-512 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-512 digest as a hexadecimal string
- Since:
- 1.4
 
- 
shaHexDeprecated.(1.11) Usesha1Hex(byte[])Calculates the SHA-1 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-1 digest as a hexadecimal string
 
- 
shaHexDeprecated.(1.11) Usesha1Hex(InputStream)Calculates the SHA-1 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-1 digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.4
 
- 
shaHexDeprecated.(1.11) Usesha1Hex(String)Calculates the SHA-1 digest and returns the value as a hexadecimal string.- Parameters:
- data- Data to digest
- Returns:
- SHA-1 digest as a hexadecimal string
 
- 
updateDigestUpdates the givenMessageDigest.- Parameters:
- messageDigest- the- MessageDigestto update
- valueToDigest- the value to update the- MessageDigestwith
- Returns:
- the updated MessageDigest
- Since:
- 1.7
 
- 
updateDigestUpdates the givenMessageDigest.- Parameters:
- messageDigest- the- MessageDigestto update
- valueToDigest- the value to update the- MessageDigestwith
- Returns:
- the updated MessageDigest
- Since:
- 1.11
 
- 
updateDigestReads through a File and updates the digest for the data- Parameters:
- digest- The MessageDigest to use (for example MD5)
- data- Data to digest
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.11
 
- 
updateDigestpublic static MessageDigest updateDigest(MessageDigest digest, InputStream inputStream) throws IOException Reads through an InputStream and updates the digest for the data- Parameters:
- digest- The MessageDigest to use (for example MD5)
- inputStream- Data to digest
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.8
 
- 
updateDigestpublic static MessageDigest updateDigest(MessageDigest digest, Path path, OpenOption... options) throws IOException Reads through a Path and updates the digest for the data- Parameters:
- digest- The MessageDigest to use (for example MD5)
- path- Data to digest
- options- options How to open the file
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.14
 
- 
updateDigestpublic static MessageDigest updateDigest(MessageDigest digest, RandomAccessFile data) throws IOException Reads through a RandomAccessFile and updates the digest for the data using non-blocking-io (NIO)- Parameters:
- digest- The MessageDigest to use (for example MD5)
- data- Data to digest
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.14
 
- 
updateDigestUpdates the givenMessageDigestfrom a String (converted to bytes using UTF-8).To update the digest using a different charset for the conversion, convert the String to a byte array using String.getBytes(java.nio.charset.Charset)and pass that to theupdateDigest(MessageDigest, byte[])method- Parameters:
- messageDigest- the- MessageDigestto update
- valueToDigest- the value to update the- MessageDigestwith; converted to bytes using- StringUtils.getBytesUtf8(String)
- Returns:
- the updated MessageDigest
- Since:
- 1.7
 
- 
digestReads through a byte array and returns the digest for the data.- Parameters:
- data- Data to digest
- Returns:
- the digest
- Since:
- 1.11
 
- 
digestReads through a ByteBuffer and returns the digest for the data- Parameters:
- data- Data to digest
- Returns:
- the digest
- Since:
- 1.11
 
- 
digestReads through a File and returns the digest for the data- Parameters:
- data- Data to digest
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.11
 
- 
digestReads through an InputStream and returns the digest for the data- Parameters:
- data- Data to digest
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.11
 
- 
digestReads through a File and returns the digest for the data- Parameters:
- data- Data to digest
- options- options How to open the file
- Returns:
- the digest
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.14
 
- 
digestReads through a byte array and returns the digest for the data.- Parameters:
- data- Data to digest treated as UTF-8 string
- Returns:
- the digest
- Since:
- 1.11
 
- 
digestAsHexReads through a byte array and returns the digest for the data.- Parameters:
- data- Data to digest
- Returns:
- the digest as a hexadecimal string
- Since:
- 1.11
 
- 
digestAsHexReads through a ByteBuffer and returns the digest for the data- Parameters:
- data- Data to digest
- Returns:
- the digest as a hexadecimal string
- Since:
- 1.11
 
- 
digestAsHexReads through a File and returns the digest for the data- Parameters:
- data- Data to digest
- Returns:
- the digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.11
 
- 
digestAsHexReads through an InputStream and returns the digest for the data- Parameters:
- data- Data to digest
- Returns:
- the digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.11
 
- 
digestAsHexReads through a File and returns the digest for the data- Parameters:
- data- Data to digest
- options- options How to open the file
- Returns:
- the digest as a hexadecimal string
- Throws:
- IOException- On error reading from the stream
- Since:
- 1.11
 
- 
digestAsHexReads through a byte array and returns the digest for the data.- Parameters:
- data- Data to digest treated as UTF-8 string
- Returns:
- the digest as a hexadecimal string
- Since:
- 1.11
 
- 
getMessageDigestReturns the message digest instance.- Returns:
- the message digest instance
- Since:
- 1.11
 
 
-