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 Summary
ConstructorDescriptionDeprecated.since 1.11; only useful to preserve binary compatibilityDigestUtils
(String name) Creates an instance using the providedMessageDigest
parameter.DigestUtils
(MessageDigest digest) Creates an instance using the providedMessageDigest
parameter. -
Method Summary
Modifier 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 MessageDigest
Gets aMessageDigest
for the givenalgorithm
.static MessageDigest
getDigest
(String algorithm, MessageDigest defaultMessageDigest) Gets aMessageDigest
for the givenalgorithm
or a default if there is a problem getting the algorithm.static MessageDigest
Gets an MD2 MessageDigest.static MessageDigest
Gets an MD5 MessageDigest.Returns the message digest instance.static MessageDigest
Gets an SHA-1 digest.static MessageDigest
Gets an SHA-256 digest.static MessageDigest
Gets an SHA3-224 digest.static MessageDigest
Returns an SHA3-256 digest.static MessageDigest
Gets an SHA3-384 digest.static MessageDigest
Gets an SHA3-512 digest.static MessageDigest
Gets an SHA-384 digest.static MessageDigest
Gets an SHA-512/224 digest.static MessageDigest
Gets an SHA-512/256 digest.static MessageDigest
Gets an SHA-512 digest.static MessageDigest
Deprecated.(1.11) UsegetSha1Digest()
static boolean
isAvailable
(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 String
md2Hex
(byte[] data) Calculates the MD2 digest and returns the value as a 32 character hexadecimal string.static String
md2Hex
(InputStream data) Calculates the MD2 digest and returns the value as a 32 character hexadecimal string.static String
Calculates 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 String
md5Hex
(byte[] data) Calculates the MD5 digest and returns the value as a 32 character hexadecimal string.static String
md5Hex
(InputStream data) Calculates the MD5 digest and returns the value as a 32 character hexadecimal string.static String
Calculates 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 String
sha1Hex
(byte[] data) Calculates the SHA-1 digest and returns the value as a hexadecimal string.static String
sha1Hex
(InputStream data) Calculates the SHA-1 digest and returns the value as a hexadecimal string.static String
Calculates 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 String
sha256Hex
(byte[] data) Calculates the SHA-256 digest and returns the value as a hexadecimal string.static String
sha256Hex
(InputStream data) Calculates the SHA-256 digest and returns the value as a hexadecimal string.static String
Calculates 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 String
sha3_224Hex
(byte[] data) Calculates the SHA3-224 digest and returns the value as a hexadecimal string.static String
sha3_224Hex
(InputStream data) Calculates the SHA3-224 digest and returns the value as a hexadecimal string.static String
sha3_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 String
sha3_256Hex
(byte[] data) Calculates the SHA3-256 digest and returns the value as a hexadecimal string.static String
sha3_256Hex
(InputStream data) Calculates the SHA3-256 digest and returns the value as a hexadecimal string.static String
sha3_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 String
sha3_384Hex
(byte[] data) Calculates the SHA3-384 digest and returns the value as a hexadecimal string.static String
sha3_384Hex
(InputStream data) Calculates the SHA3-384 digest and returns the value as a hexadecimal string.static String
sha3_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 String
sha3_512Hex
(byte[] data) Calculates the SHA3-512 digest and returns the value as a hexadecimal string.static String
sha3_512Hex
(InputStream data) Calculates the SHA3-512 digest and returns the value as a hexadecimal string.static String
sha3_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 String
sha384Hex
(byte[] data) Calculates the SHA-384 digest and returns the value as a hexadecimal string.static String
sha384Hex
(InputStream data) Calculates the SHA-384 digest and returns the value as a hexadecimal string.static String
Calculates 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 String
sha512_224Hex
(byte[] data) Calculates the SHA-512/224 digest and returns the value as a hexadecimal string.static String
sha512_224Hex
(InputStream data) Calculates the SHA-512/224 digest and returns the value as a hexadecimal string.static String
sha512_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 String
sha512_256Hex
(byte[] data) Calculates the SHA-512/256 digest and returns the value as a hexadecimal string.static String
sha512_256Hex
(InputStream data) Calculates the SHA-512/256 digest and returns the value as a hexadecimal string.static String
sha512_256Hex
(String data) Calculates the SHA-512/256 digest and returns the value as a hexadecimal string.static String
sha512Hex
(byte[] data) Calculates the SHA-512 digest and returns the value as a hexadecimal string.static String
sha512Hex
(InputStream data) Calculates the SHA-512 digest and returns the value as a hexadecimal string.static String
Calculates the SHA-512 digest and returns the value as a hexadecimal string.static String
shaHex
(byte[] data) Deprecated.(1.11) Usesha1Hex(byte[])
static String
shaHex
(InputStream data) Deprecated.(1.11) Usesha1Hex(InputStream)
static String
Deprecated.(1.11) Usesha1Hex(String)
static MessageDigest
updateDigest
(MessageDigest messageDigest, byte[] valueToDigest) Updates the givenMessageDigest
.static MessageDigest
updateDigest
(MessageDigest digest, File data) Reads through a File and updates the digest for the datastatic MessageDigest
updateDigest
(MessageDigest digest, InputStream inputStream) Reads through an InputStream and updates the digest for the datastatic MessageDigest
updateDigest
(MessageDigest digest, RandomAccessFile data) Reads through a RandomAccessFile and updates the digest for the data using non-blocking-io (NIO)static MessageDigest
updateDigest
(MessageDigest messageDigest, String valueToDigest) Updates the givenMessageDigest
from a String (converted to bytes using UTF-8).static MessageDigest
updateDigest
(MessageDigest messageDigest, ByteBuffer valueToDigest) Updates the givenMessageDigest
.static MessageDigest
updateDigest
(MessageDigest digest, Path path, OpenOption... options) Reads through a Path and updates the digest for the data
-
Constructor Details
-
DigestUtils
Deprecated.since 1.11; only useful to preserve binary compatibilityPreserves binary compatibility only. As for previous versions does not provide useful behavior -
DigestUtils
Creates an instance using the providedMessageDigest
parameter. This can then be used to create digests using methods such asdigest(byte[])
anddigestAsHex(File)
.- Parameters:
digest
- theMessageDigest
to use- Since:
- 1.11
-
DigestUtils
Creates an instance using the providedMessageDigest
parameter. This can then be used to create digests using methods such asdigest(byte[])
anddigestAsHex(File)
.- Parameters:
name
- the name of theMessageDigest
to use- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught.- Since:
- 1.11
- See Also:
-
-
Method Details
-
digest
Reads through a byte array and returns the digest for the data. Provided for symmetry with other methods.- Parameters:
messageDigest
- The MessageDigest to use (e.g. MD5)data
- Data to digest- Returns:
- the digest
- Since:
- 1.11
-
digest
Reads through a ByteBuffer and returns the digest for the data- Parameters:
messageDigest
- The MessageDigest to use (e.g. MD5)data
- Data to digest- Returns:
- the digest
- Since:
- 1.11
-
digest
Reads through a File and returns the digest for the data- Parameters:
messageDigest
- The MessageDigest to use (e.g. MD5)data
- Data to digest- Returns:
- the digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.11
-
digest
Reads through an InputStream and returns the digest for the data- Parameters:
messageDigest
- The MessageDigest to use (e.g. MD5)data
- Data to digest- Returns:
- the digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.11 (was private)
-
digest
public 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 (e.g. MD5)data
- Data to digestoptions
- options How to open the file- Returns:
- the digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.14
-
digest
Reads through a RandomAccessFile using non-blocking-io (NIO) and returns the digest for the data- Parameters:
messageDigest
- The MessageDigest to use (e.g. MD5)data
- Data to digest- Returns:
- the digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.14
-
getDigest
Gets 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:
-
getDigest
Gets aMessageDigest
for the givenalgorithm
or 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 aNoSuchAlgorithmException
is caught.- Since:
- 1.11
- See Also:
-
getMd2Digest
Gets 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:
-
getMd5Digest
Gets 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:
-
getSha1Digest
Gets 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:
-
getSha256Digest
Gets an SHA-256 digest.- 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:
-
getSha3_224Digest
Gets an SHA3-224 digest.- Returns:
- An SHA3-224 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should not happen on Oracle Java 9 and greater.- Since:
- 1.12
- See Also:
-
getSha3_256Digest
Returns an SHA3-256 digest.- Returns:
- An SHA3-256 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should not happen on Oracle Java 9 and greater.- Since:
- 1.12
- See Also:
-
getSha3_384Digest
Gets an SHA3-384 digest.- Returns:
- An SHA3-384 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should not happen on Oracle Java 9 and greater.- Since:
- 1.12
- See Also:
-
getSha3_512Digest
Gets an SHA3-512 digest.- Returns:
- An SHA3-512 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught, which should not happen on Oracle Java 9 and greater.- Since:
- 1.12
- See Also:
-
getSha384Digest
Gets an SHA-384 digest.- 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:
-
getSha512_224Digest
Gets an SHA-512/224 digest.- Returns:
- An SHA-512/224 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught.- See Also:
-
getSha512_256Digest
Gets an SHA-512/256 digest.- Returns:
- An SHA-512/256 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught.- See Also:
-
getSha512Digest
Gets an SHA-512 digest.- 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:
-
getShaDigest
Deprecated.(1.11) UsegetSha1Digest()
Gets an SHA-1 digest.- Returns:
- An SHA-1 digest instance.
- Throws:
IllegalArgumentException
- when aNoSuchAlgorithmException
is caught
-
isAvailable
Test whether the algorithm is supported.- Parameters:
messageDigestAlgorithm
- the algorithm name- Returns:
true
if the algorithm can be found- Since:
- 1.11
-
md2
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 usingStringUtils.getBytesUtf8(String)
- Returns:
- MD2 digest
- Since:
- 1.7
-
md2Hex
Calculates 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
-
md2Hex
Calculates 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
-
md2Hex
Calculates 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
-
md5
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 usingStringUtils.getBytesUtf8(String)
- Returns:
- MD5 digest
-
md5Hex
Calculates 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
-
md5Hex
Calculates 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
-
md5Hex
Calculates 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
-
sha
Deprecated.(1.11) Usesha1(byte[])
Calculates the SHA-1 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest
-
sha
Deprecated.(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
-
sha
Deprecated.(1.11) Usesha1(String)
Calculates the SHA-1 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA-1 digest
-
sha1
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 usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA-1 digest
-
sha1Hex
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
- Since:
- 1.7
-
sha1Hex
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.7
-
sha1Hex
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
- Since:
- 1.7
-
sha256
Calculates the SHA-256 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest
- Since:
- 1.4
-
sha256
Calculates 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
-
sha256
Calculates the SHA-256 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA-256 digest
- Since:
- 1.4
-
sha256Hex
Calculates 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
-
sha256Hex
Calculates 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
-
sha256Hex
Calculates 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_224
Calculates the SHA3-224 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA3-224 digest
- Since:
- 1.12
-
sha3_224
Calculates 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_224
Calculates the SHA3-224 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA3-224 digest
- Since:
- 1.12
-
sha3_224Hex
Calculates 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_224Hex
Calculates 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_224Hex
Calculates 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_256
Calculates the SHA3-256 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA3-256 digest
- Since:
- 1.12
-
sha3_256
Calculates 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_256
Calculates the SHA3-256 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA3-256 digest
- Since:
- 1.12
-
sha3_256Hex
Calculates 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_256Hex
Calculates 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_256Hex
Calculates 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_384
Calculates the SHA3-384 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA3-384 digest
- Since:
- 1.12
-
sha3_384
Calculates 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_384
Calculates the SHA3-384 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA3-384 digest
- Since:
- 1.12
-
sha3_384Hex
Calculates 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_384Hex
Calculates 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_384Hex
Calculates 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_512
Calculates the SHA3-512 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA3-512 digest
- Since:
- 1.12
-
sha3_512
Calculates 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_512
Calculates the SHA3-512 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA3-512 digest
- Since:
- 1.12
-
sha3_512Hex
Calculates 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_512Hex
Calculates 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_512Hex
Calculates 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
-
sha384
Calculates the SHA-384 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA-384 digest
- Since:
- 1.4
-
sha384
Calculates 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
-
sha384
Calculates the SHA-384 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA-384 digest
- Since:
- 1.4
-
sha384Hex
Calculates 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
-
sha384Hex
Calculates 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
-
sha384Hex
Calculates 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
-
sha512
Calculates the SHA-512 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest- Returns:
- SHA-512 digest
- Since:
- 1.4
-
sha512
Calculates 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
-
sha512
Calculates the SHA-512 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA-512 digest
- Since:
- 1.4
-
sha512_224
Calculates 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_224
Calculates 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_224
Calculates the SHA-512/224 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA-512/224 digest
- Since:
- 1.14
-
sha512_224Hex
Calculates 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_224Hex
Calculates 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_224Hex
Calculates 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_256
Calculates 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_256
Calculates 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_256
Calculates the SHA-512/256 digest and returns the value as abyte[]
.- Parameters:
data
- Data to digest; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- SHA-512/224 digest
- Since:
- 1.14
-
sha512_256Hex
Calculates 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_256Hex
Calculates 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_256Hex
Calculates 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
-
sha512Hex
Calculates 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
-
sha512Hex
Calculates 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
-
sha512Hex
Calculates 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
-
shaHex
Deprecated.(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
-
shaHex
Deprecated.(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
-
shaHex
Deprecated.(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
-
updateDigest
Updates the givenMessageDigest
.- Parameters:
messageDigest
- theMessageDigest
to updatevalueToDigest
- the value to update theMessageDigest
with- Returns:
- the updated
MessageDigest
- Since:
- 1.7
-
updateDigest
Updates the givenMessageDigest
.- Parameters:
messageDigest
- theMessageDigest
to updatevalueToDigest
- the value to update theMessageDigest
with- Returns:
- the updated
MessageDigest
- Since:
- 1.11
-
updateDigest
Reads through a File and updates the digest for the data- Parameters:
digest
- The MessageDigest to use (e.g. MD5)data
- Data to digest- Returns:
- the digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.11
-
updateDigest
public 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 (e.g. MD5)inputStream
- Data to digest- Returns:
- the digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.8
-
updateDigest
public 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 (e.g. MD5)path
- Data to digestoptions
- options How to open the file- Returns:
- the digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.14
-
updateDigest
public 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 (e.g. MD5)data
- Data to digest- Returns:
- the digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.14
-
updateDigest
Updates the givenMessageDigest
from 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
- theMessageDigest
to updatevalueToDigest
- the value to update theMessageDigest
with; converted to bytes usingStringUtils.getBytesUtf8(String)
- Returns:
- the updated
MessageDigest
- Since:
- 1.7
-
digest
Reads through a byte array and returns the digest for the data.- Parameters:
data
- Data to digest- Returns:
- the digest
- Since:
- 1.11
-
digest
Reads through a ByteBuffer and returns the digest for the data- Parameters:
data
- Data to digest- Returns:
- the digest
- Since:
- 1.11
-
digest
Reads 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
-
digest
Reads 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
-
digest
Reads through a File and returns the digest for the data- Parameters:
data
- Data to digestoptions
- options How to open the file- Returns:
- the digest
- Throws:
IOException
- On error reading from the stream- Since:
- 1.14
-
digest
Reads 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
-
digestAsHex
Reads 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
-
digestAsHex
Reads 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
-
digestAsHex
Reads 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
-
digestAsHex
Reads 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
-
digestAsHex
Reads through a File and returns the digest for the data- Parameters:
data
- Data to digestoptions
- options How to open the file- Returns:
- the digest as a hexadecimal string
- Throws:
IOException
- On error reading from the stream- Since:
- 1.11
-
digestAsHex
Reads 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
-
getMessageDigest
Returns the message digest instance.- Returns:
- the message digest instance
- Since:
- 1.11
-