Class DigestUtils


  • public class DigestUtils
    extends java.lang.Object
    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 short-hand 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:
    MessageDigestAlgorithms
    • Constructor Summary

      Constructors 
      Constructor Description
      DigestUtils()
      Deprecated.
      since 1.11; only useful to preserve binary compatibility
      DigestUtils​(java.lang.String name)
      Creates an instance using the provided MessageDigest parameter.
      DigestUtils​(java.security.MessageDigest digest)
      Creates an instance using the provided MessageDigest parameter.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      byte[] digest​(byte[] data)
      Reads through a byte array and returns the digest for the data.
      byte[] digest​(java.io.File data)
      Reads through a File and returns the digest for the data
      byte[] digest​(java.io.InputStream data)
      Reads through an InputStream and returns the digest for the data
      byte[] digest​(java.lang.String data)
      Reads through a byte array and returns the digest for the data.
      byte[] digest​(java.nio.ByteBuffer data)
      Reads through a ByteBuffer and returns the digest for the data
      byte[] digest​(java.nio.file.Path data, java.nio.file.OpenOption... options)
      Reads through a File and returns the digest for the data
      static byte[] digest​(java.security.MessageDigest messageDigest, byte[] data)
      Reads through a byte array and returns the digest for the data.
      static byte[] digest​(java.security.MessageDigest messageDigest, java.io.File data)
      Reads through a File and returns the digest for the data
      static byte[] digest​(java.security.MessageDigest messageDigest, java.io.InputStream data)
      Reads through an InputStream and returns the digest for the data
      static byte[] digest​(java.security.MessageDigest messageDigest, java.io.RandomAccessFile data)
      Reads through a RandomAccessFile using non-blocking-io (NIO) and returns the digest for the data
      static byte[] digest​(java.security.MessageDigest messageDigest, java.nio.ByteBuffer data)
      Reads through a ByteBuffer and returns the digest for the data
      static byte[] digest​(java.security.MessageDigest messageDigest, java.nio.file.Path data, java.nio.file.OpenOption... options)
      Reads through a File and returns the digest for the data
      java.lang.String digestAsHex​(byte[] data)
      Reads through a byte array and returns the digest for the data.
      java.lang.String digestAsHex​(java.io.File data)
      Reads through a File and returns the digest for the data
      java.lang.String digestAsHex​(java.io.InputStream data)
      Reads through an InputStream and returns the digest for the data
      java.lang.String digestAsHex​(java.lang.String data)
      Reads through a byte array and returns the digest for the data.
      java.lang.String digestAsHex​(java.nio.ByteBuffer data)
      Reads through a ByteBuffer and returns the digest for the data
      java.lang.String digestAsHex​(java.nio.file.Path data, java.nio.file.OpenOption... options)
      Reads through a File and returns the digest for the data
      static java.security.MessageDigest getDigest​(java.lang.String algorithm)
      Returns a MessageDigest for the given algorithm.
      static java.security.MessageDigest getDigest​(java.lang.String algorithm, java.security.MessageDigest defaultMessageDigest)
      Returns a MessageDigest for the given algorithm or a default if there is a problem getting the algorithm.
      static java.security.MessageDigest getMd2Digest()
      Returns an MD2 MessageDigest.
      static java.security.MessageDigest getMd5Digest()
      Returns an MD5 MessageDigest.
      java.security.MessageDigest getMessageDigest()
      Returns the message digest instance.
      static java.security.MessageDigest getSha1Digest()
      Returns an SHA-1 digest.
      static java.security.MessageDigest getSha256Digest()
      Returns an SHA-256 digest.
      static java.security.MessageDigest getSha3_224Digest()
      Returns an SHA3-224 digest.
      static java.security.MessageDigest getSha3_256Digest()
      Returns an SHA3-256 digest.
      static java.security.MessageDigest getSha3_384Digest()
      Returns an SHA3-384 digest.
      static java.security.MessageDigest getSha3_512Digest()
      Returns an SHA3-512 digest.
      static java.security.MessageDigest getSha384Digest()
      Returns an SHA-384 digest.
      static java.security.MessageDigest getSha512_224Digest()
      Returns an SHA-512/224 digest.
      static java.security.MessageDigest getSha512_256Digest()
      Returns an SHA-512/256 digest.
      static java.security.MessageDigest getSha512Digest()
      Returns an SHA-512 digest.
      static java.security.MessageDigest getShaDigest()
      Deprecated.
      (1.11) Use getSha1Digest()
      static boolean isAvailable​(java.lang.String messageDigestAlgorithm)
      Test whether the algorithm is supported.
      static byte[] md2​(byte[] data)
      Calculates the MD2 digest and returns the value as a 16 element byte[].
      static byte[] md2​(java.io.InputStream data)
      Calculates the MD2 digest and returns the value as a 16 element byte[].
      static byte[] md2​(java.lang.String data)
      Calculates the MD2 digest and returns the value as a 16 element byte[].
      static java.lang.String md2Hex​(byte[] data)
      Calculates the MD2 digest and returns the value as a 32 character hex string.
      static java.lang.String md2Hex​(java.io.InputStream data)
      Calculates the MD2 digest and returns the value as a 32 character hex string.
      static java.lang.String md2Hex​(java.lang.String data)
      Calculates the MD2 digest and returns the value as a 32 character hex string.
      static byte[] md5​(byte[] data)
      Calculates the MD5 digest and returns the value as a 16 element byte[].
      static byte[] md5​(java.io.InputStream data)
      Calculates the MD5 digest and returns the value as a 16 element byte[].
      static byte[] md5​(java.lang.String data)
      Calculates the MD5 digest and returns the value as a 16 element byte[].
      static java.lang.String md5Hex​(byte[] data)
      Calculates the MD5 digest and returns the value as a 32 character hex string.
      static java.lang.String md5Hex​(java.io.InputStream data)
      Calculates the MD5 digest and returns the value as a 32 character hex string.
      static java.lang.String md5Hex​(java.lang.String data)
      Calculates the MD5 digest and returns the value as a 32 character hex string.
      static byte[] sha​(byte[] data)
      Deprecated.
      (1.11) Use sha1(byte[])
      static byte[] sha​(java.io.InputStream data)
      Deprecated.
      static byte[] sha​(java.lang.String data)
      Deprecated.
      (1.11) Use sha1(String)
      static byte[] sha1​(byte[] data)
      Calculates the SHA-1 digest and returns the value as a byte[].
      static byte[] sha1​(java.io.InputStream data)
      Calculates the SHA-1 digest and returns the value as a byte[].
      static byte[] sha1​(java.lang.String data)
      Calculates the SHA-1 digest and returns the value as a byte[].
      static java.lang.String sha1Hex​(byte[] data)
      Calculates the SHA-1 digest and returns the value as a hex string.
      static java.lang.String sha1Hex​(java.io.InputStream data)
      Calculates the SHA-1 digest and returns the value as a hex string.
      static java.lang.String sha1Hex​(java.lang.String data)
      Calculates the SHA-1 digest and returns the value as a hex string.
      static byte[] sha256​(byte[] data)
      Calculates the SHA-256 digest and returns the value as a byte[].
      static byte[] sha256​(java.io.InputStream data)
      Calculates the SHA-256 digest and returns the value as a byte[].
      static byte[] sha256​(java.lang.String data)
      Calculates the SHA-256 digest and returns the value as a byte[].
      static java.lang.String sha256Hex​(byte[] data)
      Calculates the SHA-256 digest and returns the value as a hex string.
      static java.lang.String sha256Hex​(java.io.InputStream data)
      Calculates the SHA-256 digest and returns the value as a hex string.
      static java.lang.String sha256Hex​(java.lang.String data)
      Calculates the SHA-256 digest and returns the value as a hex string.
      static byte[] sha3_224​(byte[] data)
      Calculates the SHA3-224 digest and returns the value as a byte[].
      static byte[] sha3_224​(java.io.InputStream data)
      Calculates the SHA3-224 digest and returns the value as a byte[].
      static byte[] sha3_224​(java.lang.String data)
      Calculates the SHA3-224 digest and returns the value as a byte[].
      static java.lang.String sha3_224Hex​(byte[] data)
      Calculates the SHA3-224 digest and returns the value as a hex string.
      static java.lang.String sha3_224Hex​(java.io.InputStream data)
      Calculates the SHA3-224 digest and returns the value as a hex string.
      static java.lang.String sha3_224Hex​(java.lang.String data)
      Calculates the SHA3-224 digest and returns the value as a hex string.
      static byte[] sha3_256​(byte[] data)
      Calculates the SHA3-256 digest and returns the value as a byte[].
      static byte[] sha3_256​(java.io.InputStream data)
      Calculates the SHA3-256 digest and returns the value as a byte[].
      static byte[] sha3_256​(java.lang.String data)
      Calculates the SHA3-256 digest and returns the value as a byte[].
      static java.lang.String sha3_256Hex​(byte[] data)
      Calculates the SHA3-256 digest and returns the value as a hex string.
      static java.lang.String sha3_256Hex​(java.io.InputStream data)
      Calculates the SHA3-256 digest and returns the value as a hex string.
      static java.lang.String sha3_256Hex​(java.lang.String data)
      Calculates the SHA3-256 digest and returns the value as a hex string.
      static byte[] sha3_384​(byte[] data)
      Calculates the SHA3-384 digest and returns the value as a byte[].
      static byte[] sha3_384​(java.io.InputStream data)
      Calculates the SHA3-384 digest and returns the value as a byte[].
      static byte[] sha3_384​(java.lang.String data)
      Calculates the SHA3-384 digest and returns the value as a byte[].
      static java.lang.String sha3_384Hex​(byte[] data)
      Calculates the SHA3-384 digest and returns the value as a hex string.
      static java.lang.String sha3_384Hex​(java.io.InputStream data)
      Calculates the SHA3-384 digest and returns the value as a hex string.
      static java.lang.String sha3_384Hex​(java.lang.String data)
      Calculates the SHA3-384 digest and returns the value as a hex string.
      static byte[] sha3_512​(byte[] data)
      Calculates the SHA3-512 digest and returns the value as a byte[].
      static byte[] sha3_512​(java.io.InputStream data)
      Calculates the SHA3-512 digest and returns the value as a byte[].
      static byte[] sha3_512​(java.lang.String data)
      Calculates the SHA3-512 digest and returns the value as a byte[].
      static java.lang.String sha3_512Hex​(byte[] data)
      Calculates the SHA3-512 digest and returns the value as a hex string.
      static java.lang.String sha3_512Hex​(java.io.InputStream data)
      Calculates the SHA3-512 digest and returns the value as a hex string.
      static java.lang.String sha3_512Hex​(java.lang.String data)
      Calculates the SHA3-512 digest and returns the value as a hex string.
      static byte[] sha384​(byte[] data)
      Calculates the SHA-384 digest and returns the value as a byte[].
      static byte[] sha384​(java.io.InputStream data)
      Calculates the SHA-384 digest and returns the value as a byte[].
      static byte[] sha384​(java.lang.String data)
      Calculates the SHA-384 digest and returns the value as a byte[].
      static java.lang.String sha384Hex​(byte[] data)
      Calculates the SHA-384 digest and returns the value as a hex string.
      static java.lang.String sha384Hex​(java.io.InputStream data)
      Calculates the SHA-384 digest and returns the value as a hex string.
      static java.lang.String sha384Hex​(java.lang.String data)
      Calculates the SHA-384 digest and returns the value as a hex string.
      static byte[] sha512​(byte[] data)
      Calculates the SHA-512 digest and returns the value as a byte[].
      static byte[] sha512​(java.io.InputStream data)
      Calculates the SHA-512 digest and returns the value as a byte[].
      static byte[] sha512​(java.lang.String data)
      Calculates the SHA-512 digest and returns the value as a byte[].
      static byte[] sha512_224​(byte[] data)
      Calculates the SHA-512/224 digest and returns the value as a byte[].
      static byte[] sha512_224​(java.io.InputStream data)
      Calculates the SHA-512/224 digest and returns the value as a byte[].
      static byte[] sha512_224​(java.lang.String data)
      Calculates the SHA-512/224 digest and returns the value as a byte[].
      static java.lang.String sha512_224Hex​(byte[] data)
      Calculates the SHA-512/224 digest and returns the value as a hex string.
      static java.lang.String sha512_224Hex​(java.io.InputStream data)
      Calculates the SHA-512/224 digest and returns the value as a hex string.
      static java.lang.String sha512_224Hex​(java.lang.String data)
      Calculates the SHA-512/224 digest and returns the value as a hex string.
      static byte[] sha512_256​(byte[] data)
      Calculates the SHA-512/256 digest and returns the value as a byte[].
      static byte[] sha512_256​(java.io.InputStream data)
      Calculates the SHA-512/256 digest and returns the value as a byte[].
      static byte[] sha512_256​(java.lang.String data)
      Calculates the SHA-512/256 digest and returns the value as a byte[].
      static java.lang.String sha512_256Hex​(byte[] data)
      Calculates the SHA-512/256 digest and returns the value as a hex string.
      static java.lang.String sha512_256Hex​(java.io.InputStream data)
      Calculates the SHA-512/256 digest and returns the value as a hex string.
      static java.lang.String sha512_256Hex​(java.lang.String data)
      Calculates the SHA-512/256 digest and returns the value as a hex string.
      static java.lang.String sha512Hex​(byte[] data)
      Calculates the SHA-512 digest and returns the value as a hex string.
      static java.lang.String sha512Hex​(java.io.InputStream data)
      Calculates the SHA-512 digest and returns the value as a hex string.
      static java.lang.String sha512Hex​(java.lang.String data)
      Calculates the SHA-512 digest and returns the value as a hex string.
      static java.lang.String shaHex​(byte[] data)
      Deprecated.
      (1.11) Use sha1Hex(byte[])
      static java.lang.String shaHex​(java.io.InputStream data)
      Deprecated.
      static java.lang.String shaHex​(java.lang.String data)
      Deprecated.
      (1.11) Use sha1Hex(String)
      static java.security.MessageDigest updateDigest​(java.security.MessageDigest messageDigest, byte[] valueToDigest)
      Updates the given MessageDigest.
      static java.security.MessageDigest updateDigest​(java.security.MessageDigest digest, java.io.File data)
      Reads through a File and updates the digest for the data
      static java.security.MessageDigest updateDigest​(java.security.MessageDigest digest, java.io.InputStream inputStream)
      Reads through an InputStream and updates the digest for the data
      static java.security.MessageDigest updateDigest​(java.security.MessageDigest digest, java.io.RandomAccessFile data)
      Reads through a RandomAccessFile and updates the digest for the data using non-blocking-io (NIO)
      static java.security.MessageDigest updateDigest​(java.security.MessageDigest messageDigest, java.lang.String valueToDigest)
      Updates the given MessageDigest from a String (converted to bytes using UTF-8).
      static java.security.MessageDigest updateDigest​(java.security.MessageDigest messageDigest, java.nio.ByteBuffer valueToDigest)
      Updates the given MessageDigest.
      static java.security.MessageDigest updateDigest​(java.security.MessageDigest digest, java.nio.file.Path path, java.nio.file.OpenOption... options)
      Reads through a Path and updates the digest for the data
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DigestUtils

        @Deprecated
        public DigestUtils()
        Deprecated.
        since 1.11; only useful to preserve binary compatibility
        Preserves binary compatibility only. As for previous versions does not provide useful behavior
      • DigestUtils

        public DigestUtils​(java.security.MessageDigest digest)
        Creates an instance using the provided MessageDigest parameter. This can then be used to create digests using methods such as digest(byte[]) and digestAsHex(File).
        Parameters:
        digest - the MessageDigest to use
        Since:
        1.11
      • DigestUtils

        public DigestUtils​(java.lang.String name)
        Creates an instance using the provided MessageDigest parameter. This can then be used to create digests using methods such as digest(byte[]) and digestAsHex(File).
        Parameters:
        name - the name of the MessageDigest to use
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught.
        Since:
        1.11
        See Also:
        getDigest(String)
    • Method Detail

      • digest

        public static byte[] digest​(java.security.MessageDigest messageDigest,
                                    byte[] data)
        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

        public static byte[] digest​(java.security.MessageDigest messageDigest,
                                    java.nio.ByteBuffer data)
        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

        public static byte[] digest​(java.security.MessageDigest messageDigest,
                                    java.io.File data)
                             throws java.io.IOException
        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:
        java.io.IOException - On error reading from the stream
        Since:
        1.11
      • digest

        public static byte[] digest​(java.security.MessageDigest messageDigest,
                                    java.io.InputStream data)
                             throws java.io.IOException
        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:
        java.io.IOException - On error reading from the stream
        Since:
        1.11 (was private)
      • digest

        public static byte[] digest​(java.security.MessageDigest messageDigest,
                                    java.nio.file.Path data,
                                    java.nio.file.OpenOption... options)
                             throws java.io.IOException
        Reads through a File and returns the digest for the data
        Parameters:
        messageDigest - The MessageDigest to use (e.g. MD5)
        data - Data to digest
        options - options How to open the file
        Returns:
        the digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.14
      • digest

        public static byte[] digest​(java.security.MessageDigest messageDigest,
                                    java.io.RandomAccessFile data)
                             throws java.io.IOException
        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:
        java.io.IOException - On error reading from the stream
        Since:
        1.14
      • getDigest

        public static java.security.MessageDigest getDigest​(java.lang.String algorithm)
        Returns a MessageDigest for the given 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.
        Returns:
        A digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught.
        See Also:
        MessageDigest.getInstance(String)
      • getDigest

        public static java.security.MessageDigest getDigest​(java.lang.String algorithm,
                                                            java.security.MessageDigest defaultMessageDigest)
        Returns a MessageDigest for the given algorithm 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:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught.
        Since:
        1.11
        See Also:
        MessageDigest.getInstance(String)
      • getMd2Digest

        public static java.security.MessageDigest getMd2Digest()
        Returns an MD2 MessageDigest.
        Returns:
        An MD2 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because MD2 is a built-in algorithm
        Since:
        1.7
        See Also:
        MessageDigestAlgorithms.MD2
      • getMd5Digest

        public static java.security.MessageDigest getMd5Digest()
        Returns an MD5 MessageDigest.
        Returns:
        An MD5 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because MD5 is a built-in algorithm
        See Also:
        MessageDigestAlgorithms.MD5
      • getSha1Digest

        public static java.security.MessageDigest getSha1Digest()
        Returns an SHA-1 digest.
        Returns:
        An SHA-1 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-1 is a built-in algorithm
        Since:
        1.7
        See Also:
        MessageDigestAlgorithms.SHA_1
      • getSha256Digest

        public static java.security.MessageDigest getSha256Digest()
        Returns an SHA-256 digest.
        Returns:
        An SHA-256 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-256 is a built-in algorithm
        See Also:
        MessageDigestAlgorithms.SHA_256
      • getSha3_224Digest

        public static java.security.MessageDigest getSha3_224Digest()
        Returns an SHA3-224 digest.
        Returns:
        An SHA3-224 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should not happen on Oracle Java 9 andgreater.
        Since:
        1.12
        See Also:
        MessageDigestAlgorithms.SHA3_224
      • getSha3_256Digest

        public static java.security.MessageDigest getSha3_256Digest()
        Returns an SHA3-256 digest.
        Returns:
        An SHA3-256 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should not happen on Oracle Java 9 and greater.
        Since:
        1.12
        See Also:
        MessageDigestAlgorithms.SHA3_256
      • getSha3_384Digest

        public static java.security.MessageDigest getSha3_384Digest()
        Returns an SHA3-384 digest.
        Returns:
        An SHA3-384 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should not happen on Oracle Java 9 and greater.
        Since:
        1.12
        See Also:
        MessageDigestAlgorithms.SHA3_384
      • getSha3_512Digest

        public static java.security.MessageDigest getSha3_512Digest()
        Returns an SHA3-512 digest.
        Returns:
        An SHA3-512 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should not happen on Oracle Java 9 and greater.
        Since:
        1.12
        See Also:
        MessageDigestAlgorithms.SHA3_512
      • getSha384Digest

        public static java.security.MessageDigest getSha384Digest()
        Returns an SHA-384 digest.
        Returns:
        An SHA-384 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-384 is a built-in algorithm
        See Also:
        MessageDigestAlgorithms.SHA_384
      • getSha512_224Digest

        public static java.security.MessageDigest getSha512_224Digest()
        Returns an SHA-512/224 digest.
        Returns:
        An SHA-512/224 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught.
        See Also:
        MessageDigestAlgorithms.SHA_512_224
      • getSha512_256Digest

        public static java.security.MessageDigest getSha512_256Digest()
        Returns an SHA-512/256 digest.
        Returns:
        An SHA-512/256 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught.
        See Also:
        MessageDigestAlgorithms.SHA_512_224
      • getSha512Digest

        public static java.security.MessageDigest getSha512Digest()
        Returns an SHA-512 digest.
        Returns:
        An SHA-512 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-512 is a built-in algorithm
        See Also:
        MessageDigestAlgorithms.SHA_512
      • getShaDigest

        @Deprecated
        public static java.security.MessageDigest getShaDigest()
        Deprecated.
        (1.11) Use getSha1Digest()
        Returns an SHA-1 digest.
        Returns:
        An SHA-1 digest instance.
        Throws:
        java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught
      • isAvailable

        public static boolean isAvailable​(java.lang.String messageDigestAlgorithm)
        Test whether the algorithm is supported.
        Parameters:
        messageDigestAlgorithm - the algorithm name
        Returns:
        true if the algorithm can be found
        Since:
        1.11
      • md2

        public static byte[] md2​(byte[] data)
        Calculates the MD2 digest and returns the value as a 16 element byte[].
        Parameters:
        data - Data to digest
        Returns:
        MD2 digest
        Since:
        1.7
      • md2

        public static byte[] md2​(java.io.InputStream data)
                          throws java.io.IOException
        Calculates the MD2 digest and returns the value as a 16 element byte[].
        Parameters:
        data - Data to digest
        Returns:
        MD2 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.7
      • md2

        public static byte[] md2​(java.lang.String data)
        Calculates the MD2 digest and returns the value as a 16 element byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        MD2 digest
        Since:
        1.7
      • md2Hex

        public static java.lang.String md2Hex​(byte[] data)
        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

        public static java.lang.String md2Hex​(java.io.InputStream data)
                                       throws java.io.IOException
        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:
        java.io.IOException - On error reading from the stream
        Since:
        1.7
      • md2Hex

        public static java.lang.String md2Hex​(java.lang.String data)
        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
      • md5

        public static byte[] md5​(byte[] data)
        Calculates the MD5 digest and returns the value as a 16 element byte[].
        Parameters:
        data - Data to digest
        Returns:
        MD5 digest
      • md5

        public static byte[] md5​(java.io.InputStream data)
                          throws java.io.IOException
        Calculates the MD5 digest and returns the value as a 16 element byte[].
        Parameters:
        data - Data to digest
        Returns:
        MD5 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • md5

        public static byte[] md5​(java.lang.String data)
        Calculates the MD5 digest and returns the value as a 16 element byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        MD5 digest
      • md5Hex

        public static java.lang.String md5Hex​(byte[] data)
        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

        public static java.lang.String md5Hex​(java.io.InputStream data)
                                       throws java.io.IOException
        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:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • md5Hex

        public static java.lang.String md5Hex​(java.lang.String data)
        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
      • sha

        @Deprecated
        public static byte[] sha​(byte[] data)
        Deprecated.
        (1.11) Use sha1(byte[])
        Calculates the SHA-1 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-1 digest
      • sha

        @Deprecated
        public static byte[] sha​(java.io.InputStream data)
                          throws java.io.IOException
        Deprecated.
        Calculates the SHA-1 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-1 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • sha

        @Deprecated
        public static byte[] sha​(java.lang.String data)
        Deprecated.
        (1.11) Use sha1(String)
        Calculates the SHA-1 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-1 digest
      • sha1

        public static byte[] sha1​(byte[] data)
        Calculates the SHA-1 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-1 digest
        Since:
        1.7
      • sha1

        public static byte[] sha1​(java.io.InputStream data)
                           throws java.io.IOException
        Calculates the SHA-1 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-1 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.7
      • sha1

        public static byte[] sha1​(java.lang.String data)
        Calculates the SHA-1 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA-1 digest
      • sha1Hex

        public static java.lang.String sha1Hex​(byte[] data)
        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

        public static java.lang.String sha1Hex​(java.io.InputStream data)
                                        throws java.io.IOException
        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:
        java.io.IOException - On error reading from the stream
        Since:
        1.7
      • sha1Hex

        public static java.lang.String sha1Hex​(java.lang.String data)
        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
      • sha256

        public static byte[] sha256​(byte[] data)
        Calculates the SHA-256 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-256 digest
        Since:
        1.4
      • sha256

        public static byte[] sha256​(java.io.InputStream data)
                             throws java.io.IOException
        Calculates the SHA-256 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-256 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • sha256

        public static byte[] sha256​(java.lang.String data)
        Calculates the SHA-256 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA-256 digest
        Since:
        1.4
      • sha256Hex

        public static java.lang.String sha256Hex​(byte[] data)
        Calculates the SHA-256 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-256 digest as a hex string
        Since:
        1.4
      • sha256Hex

        public static java.lang.String sha256Hex​(java.io.InputStream data)
                                          throws java.io.IOException
        Calculates the SHA-256 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-256 digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • sha256Hex

        public static java.lang.String sha256Hex​(java.lang.String data)
        Calculates the SHA-256 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-256 digest as a hex string
        Since:
        1.4
      • sha3_224

        public static byte[] sha3_224​(byte[] data)
        Calculates the SHA3-224 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA3-224 digest
        Since:
        1.12
      • sha3_224

        public static byte[] sha3_224​(java.io.InputStream data)
                               throws java.io.IOException
        Calculates the SHA3-224 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA3-224 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.12
      • sha3_224

        public static byte[] sha3_224​(java.lang.String data)
        Calculates the SHA3-224 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA3-224 digest
        Since:
        1.12
      • sha3_224Hex

        public static java.lang.String sha3_224Hex​(byte[] data)
        Calculates the SHA3-224 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-224 digest as a hex string
        Since:
        1.12
      • sha3_224Hex

        public static java.lang.String sha3_224Hex​(java.io.InputStream data)
                                            throws java.io.IOException
        Calculates the SHA3-224 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-224 digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.12
      • sha3_224Hex

        public static java.lang.String sha3_224Hex​(java.lang.String data)
        Calculates the SHA3-224 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-224 digest as a hex string
        Since:
        1.12
      • sha3_256

        public static byte[] sha3_256​(byte[] data)
        Calculates the SHA3-256 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA3-256 digest
        Since:
        1.12
      • sha3_256

        public static byte[] sha3_256​(java.io.InputStream data)
                               throws java.io.IOException
        Calculates the SHA3-256 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA3-256 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.12
      • sha3_256

        public static byte[] sha3_256​(java.lang.String data)
        Calculates the SHA3-256 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA3-256 digest
        Since:
        1.12
      • sha3_256Hex

        public static java.lang.String sha3_256Hex​(byte[] data)
        Calculates the SHA3-256 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-256 digest as a hex string
        Since:
        1.12
      • sha3_256Hex

        public static java.lang.String sha3_256Hex​(java.io.InputStream data)
                                            throws java.io.IOException
        Calculates the SHA3-256 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-256 digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.12
      • sha3_256Hex

        public static java.lang.String sha3_256Hex​(java.lang.String data)
        Calculates the SHA3-256 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-256 digest as a hex string
        Since:
        1.12
      • sha3_384

        public static byte[] sha3_384​(byte[] data)
        Calculates the SHA3-384 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA3-384 digest
        Since:
        1.12
      • sha3_384

        public static byte[] sha3_384​(java.io.InputStream data)
                               throws java.io.IOException
        Calculates the SHA3-384 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA3-384 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.12
      • sha3_384

        public static byte[] sha3_384​(java.lang.String data)
        Calculates the SHA3-384 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA3-384 digest
        Since:
        1.12
      • sha3_384Hex

        public static java.lang.String sha3_384Hex​(byte[] data)
        Calculates the SHA3-384 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-384 digest as a hex string
        Since:
        1.12
      • sha3_384Hex

        public static java.lang.String sha3_384Hex​(java.io.InputStream data)
                                            throws java.io.IOException
        Calculates the SHA3-384 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-384 digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.12
      • sha3_384Hex

        public static java.lang.String sha3_384Hex​(java.lang.String data)
        Calculates the SHA3-384 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-384 digest as a hex string
        Since:
        1.12
      • sha3_512

        public static byte[] sha3_512​(byte[] data)
        Calculates the SHA3-512 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA3-512 digest
        Since:
        1.12
      • sha3_512

        public static byte[] sha3_512​(java.io.InputStream data)
                               throws java.io.IOException
        Calculates the SHA3-512 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA3-512 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.12
      • sha3_512

        public static byte[] sha3_512​(java.lang.String data)
        Calculates the SHA3-512 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA3-512 digest
        Since:
        1.12
      • sha3_512Hex

        public static java.lang.String sha3_512Hex​(byte[] data)
        Calculates the SHA3-512 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-512 digest as a hex string
        Since:
        1.12
      • sha3_512Hex

        public static java.lang.String sha3_512Hex​(java.io.InputStream data)
                                            throws java.io.IOException
        Calculates the SHA3-512 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-512 digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.12
      • sha3_512Hex

        public static java.lang.String sha3_512Hex​(java.lang.String data)
        Calculates the SHA3-512 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA3-512 digest as a hex string
        Since:
        1.12
      • sha384

        public static byte[] sha384​(byte[] data)
        Calculates the SHA-384 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-384 digest
        Since:
        1.4
      • sha384

        public static byte[] sha384​(java.io.InputStream data)
                             throws java.io.IOException
        Calculates the SHA-384 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-384 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • sha384

        public static byte[] sha384​(java.lang.String data)
        Calculates the SHA-384 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA-384 digest
        Since:
        1.4
      • sha384Hex

        public static java.lang.String sha384Hex​(byte[] data)
        Calculates the SHA-384 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-384 digest as a hex string
        Since:
        1.4
      • sha384Hex

        public static java.lang.String sha384Hex​(java.io.InputStream data)
                                          throws java.io.IOException
        Calculates the SHA-384 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-384 digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • sha384Hex

        public static java.lang.String sha384Hex​(java.lang.String data)
        Calculates the SHA-384 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-384 digest as a hex string
        Since:
        1.4
      • sha512

        public static byte[] sha512​(byte[] data)
        Calculates the SHA-512 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-512 digest
        Since:
        1.4
      • sha512

        public static byte[] sha512​(java.io.InputStream data)
                             throws java.io.IOException
        Calculates the SHA-512 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-512 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • sha512

        public static byte[] sha512​(java.lang.String data)
        Calculates the SHA-512 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA-512 digest
        Since:
        1.4
      • sha512_224

        public static byte[] sha512_224​(byte[] data)
        Calculates the SHA-512/224 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/224 digest
        Since:
        1.14
      • sha512_224

        public static byte[] sha512_224​(java.io.InputStream data)
                                 throws java.io.IOException
        Calculates the SHA-512/224 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/224 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.14
      • sha512_224

        public static byte[] sha512_224​(java.lang.String data)
        Calculates the SHA-512/224 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA-512/224 digest
        Since:
        1.14
      • sha512_224Hex

        public static java.lang.String sha512_224Hex​(byte[] data)
        Calculates the SHA-512/224 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/224 digest as a hex string
        Since:
        1.14
      • sha512_224Hex

        public static java.lang.String sha512_224Hex​(java.io.InputStream data)
                                              throws java.io.IOException
        Calculates the SHA-512/224 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/224 digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.14
      • sha512_224Hex

        public static java.lang.String sha512_224Hex​(java.lang.String data)
        Calculates the SHA-512/224 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/224 digest as a hex string
        Since:
        1.14
      • sha512_256

        public static byte[] sha512_256​(byte[] data)
        Calculates the SHA-512/256 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/256 digest
        Since:
        1.14
      • sha512_256

        public static byte[] sha512_256​(java.io.InputStream data)
                                 throws java.io.IOException
        Calculates the SHA-512/256 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/256 digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.14
      • sha512_256

        public static byte[] sha512_256​(java.lang.String data)
        Calculates the SHA-512/256 digest and returns the value as a byte[].
        Parameters:
        data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        SHA-512/224 digest
        Since:
        1.14
      • sha512_256Hex

        public static java.lang.String sha512_256Hex​(byte[] data)
        Calculates the SHA-512/256 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/256 digest as a hex string
        Since:
        1.14
      • sha512_256Hex

        public static java.lang.String sha512_256Hex​(java.io.InputStream data)
                                              throws java.io.IOException
        Calculates the SHA-512/256 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/256 digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.14
      • sha512_256Hex

        public static java.lang.String sha512_256Hex​(java.lang.String data)
        Calculates the SHA-512/256 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-512/256 digest as a hex string
        Since:
        1.14
      • sha512Hex

        public static java.lang.String sha512Hex​(byte[] data)
        Calculates the SHA-512 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-512 digest as a hex string
        Since:
        1.4
      • sha512Hex

        public static java.lang.String sha512Hex​(java.io.InputStream data)
                                          throws java.io.IOException
        Calculates the SHA-512 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-512 digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • sha512Hex

        public static java.lang.String sha512Hex​(java.lang.String data)
        Calculates the SHA-512 digest and returns the value as a hex string.
        Parameters:
        data - Data to digest
        Returns:
        SHA-512 digest as a hex string
        Since:
        1.4
      • shaHex

        @Deprecated
        public static java.lang.String shaHex​(byte[] data)
        Deprecated.
        (1.11) Use sha1Hex(byte[])
        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
      • shaHex

        @Deprecated
        public static java.lang.String shaHex​(java.io.InputStream data)
                                       throws java.io.IOException
        Deprecated.
        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:
        java.io.IOException - On error reading from the stream
        Since:
        1.4
      • shaHex

        @Deprecated
        public static java.lang.String shaHex​(java.lang.String data)
        Deprecated.
        (1.11) Use sha1Hex(String)
        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
      • updateDigest

        public static java.security.MessageDigest updateDigest​(java.security.MessageDigest messageDigest,
                                                               byte[] valueToDigest)
        Updates the given MessageDigest.
        Parameters:
        messageDigest - the MessageDigest to update
        valueToDigest - the value to update the MessageDigest with
        Returns:
        the updated MessageDigest
        Since:
        1.7
      • updateDigest

        public static java.security.MessageDigest updateDigest​(java.security.MessageDigest messageDigest,
                                                               java.nio.ByteBuffer valueToDigest)
        Updates the given MessageDigest.
        Parameters:
        messageDigest - the MessageDigest to update
        valueToDigest - the value to update the MessageDigest with
        Returns:
        the updated MessageDigest
        Since:
        1.11
      • updateDigest

        public static java.security.MessageDigest updateDigest​(java.security.MessageDigest digest,
                                                               java.io.File data)
                                                        throws java.io.IOException
        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:
        java.io.IOException - On error reading from the stream
        Since:
        1.11
      • updateDigest

        public static java.security.MessageDigest updateDigest​(java.security.MessageDigest digest,
                                                               java.io.InputStream inputStream)
                                                        throws java.io.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:
        java.io.IOException - On error reading from the stream
        Since:
        1.8
      • updateDigest

        public static java.security.MessageDigest updateDigest​(java.security.MessageDigest digest,
                                                               java.nio.file.Path path,
                                                               java.nio.file.OpenOption... options)
                                                        throws java.io.IOException
        Reads through a Path and updates the digest for the data
        Parameters:
        digest - The MessageDigest to use (e.g. MD5)
        path - Data to digest
        options - options How to open the file
        Returns:
        the digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.14
      • updateDigest

        public static java.security.MessageDigest updateDigest​(java.security.MessageDigest digest,
                                                               java.io.RandomAccessFile data)
                                                        throws java.io.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:
        java.io.IOException - On error reading from the stream
        Since:
        1.14
      • updateDigest

        public static java.security.MessageDigest updateDigest​(java.security.MessageDigest messageDigest,
                                                               java.lang.String valueToDigest)
        Updates the given MessageDigest 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 the updateDigest(MessageDigest, byte[]) method

        Parameters:
        messageDigest - the MessageDigest to update
        valueToDigest - the value to update the MessageDigest with; converted to bytes using StringUtils.getBytesUtf8(String)
        Returns:
        the updated MessageDigest
        Since:
        1.7
      • digest

        public byte[] digest​(byte[] data)
        Reads through a byte array and returns the digest for the data.
        Parameters:
        data - Data to digest
        Returns:
        the digest
        Since:
        1.11
      • digest

        public byte[] digest​(java.nio.ByteBuffer data)
        Reads through a ByteBuffer and returns the digest for the data
        Parameters:
        data - Data to digest
        Returns:
        the digest
        Since:
        1.11
      • digest

        public byte[] digest​(java.io.File data)
                      throws java.io.IOException
        Reads through a File and returns the digest for the data
        Parameters:
        data - Data to digest
        Returns:
        the digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.11
      • digest

        public byte[] digest​(java.io.InputStream data)
                      throws java.io.IOException
        Reads through an InputStream and returns the digest for the data
        Parameters:
        data - Data to digest
        Returns:
        the digest
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.11
      • digest

        public byte[] digest​(java.nio.file.Path data,
                             java.nio.file.OpenOption... options)
                      throws java.io.IOException
        Reads 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:
        java.io.IOException - On error reading from the stream
        Since:
        1.14
      • digest

        public byte[] digest​(java.lang.String data)
        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

        public java.lang.String digestAsHex​(byte[] data)
        Reads through a byte array and returns the digest for the data.
        Parameters:
        data - Data to digest
        Returns:
        the digest as a hex string
        Since:
        1.11
      • digestAsHex

        public java.lang.String digestAsHex​(java.nio.ByteBuffer data)
        Reads through a ByteBuffer and returns the digest for the data
        Parameters:
        data - Data to digest
        Returns:
        the digest as a hex string
        Since:
        1.11
      • digestAsHex

        public java.lang.String digestAsHex​(java.io.File data)
                                     throws java.io.IOException
        Reads through a File and returns the digest for the data
        Parameters:
        data - Data to digest
        Returns:
        the digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.11
      • digestAsHex

        public java.lang.String digestAsHex​(java.io.InputStream data)
                                     throws java.io.IOException
        Reads through an InputStream and returns the digest for the data
        Parameters:
        data - Data to digest
        Returns:
        the digest as a hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.11
      • digestAsHex

        public java.lang.String digestAsHex​(java.nio.file.Path data,
                                            java.nio.file.OpenOption... options)
                                     throws java.io.IOException
        Reads 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 hex string
        Throws:
        java.io.IOException - On error reading from the stream
        Since:
        1.11
      • digestAsHex

        public java.lang.String digestAsHex​(java.lang.String data)
        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 hex string
        Since:
        1.11
      • getMessageDigest

        public java.security.MessageDigest getMessageDigest()
        Returns the message digest instance.
        Returns:
        the message digest instance
        Since:
        1.11