Class DigestUtils


  • public final class DigestUtils
    extends java.lang.Object
    • Constructor Detail

      • DigestUtils

        private DigestUtils()
    • Method Detail

      • checkSupported

        public static boolean checkSupported​(java.lang.String algorithm)
        Parameters:
        algorithm - The digest algorithm - never null/empty
        Returns:
        true if this digest algorithm is supported
        See Also:
        SecurityUtils.getMessageDigest(String)
      • findDigestByAlgorithm

        public static <D extends Digest> D findDigestByAlgorithm​(java.lang.String algo,
                                                                 java.util.Comparator<? super java.lang.String> comp,
                                                                 java.util.Collection<? extends D> digests)
        Type Parameters:
        D - The generic type of digest factory
        Parameters:
        algo - The required algorithm name - ignored if null/empty
        comp - The Comparator to use to compare algorithm names
        digests - The factories to check - ignored if null/empty
        Returns:
        The first DigestFactory whose algorithm matches the required one according to the comparator - null if no match found
      • findFactoryByAlgorithm

        public static <F extends DigestFactory> F findFactoryByAlgorithm​(java.lang.String algo,
                                                                         java.util.Comparator<? super java.lang.String> comp,
                                                                         java.util.Collection<? extends F> factories)
        Type Parameters:
        F - The generic type of digest factory
        Parameters:
        algo - The required algorithm name - ignored if null/empty
        comp - The Comparator to use to compare algorithm names
        factories - The factories to check - ignored if null/empty
        Returns:
        The first DigestFactory whose algorithm matches the required one according to the comparator - null if no match found
      • getFingerPrint

        public static java.lang.String getFingerPrint​(Factory<? extends Digest> f,
                                                      java.lang.String s)
                                               throws java.lang.Exception
        Parameters:
        f - The Factory to create the Digest to use
        s - The String to digest - ignored if null/empty, otherwise its UTF-8 representation is used as input for the fingerprint
        Returns:
        The fingerprint - null if null/empty input
        Throws:
        java.lang.Exception - If failed to calculate the digest
        See Also:
        getFingerPrint(Digest, String, Charset)
      • getFingerPrint

        public static java.lang.String getFingerPrint​(Factory<? extends Digest> f,
                                                      java.lang.String s,
                                                      java.nio.charset.Charset charset)
                                               throws java.lang.Exception
        Parameters:
        f - The Factory to create the Digest to use
        s - The String to digest - ignored if null/empty
        charset - The Charset to use in order to convert the string to its byte representation to use as input for the fingerprint
        Returns:
        The fingerprint - null if null/empty input
        Throws:
        java.lang.Exception - If failed to calculate the digest
      • getFingerPrint

        public static java.lang.String getFingerPrint​(Digest d,
                                                      java.lang.String s)
                                               throws java.lang.Exception
        Parameters:
        d - The Digest to use
        s - The String to digest - ignored if null/empty, otherwise its UTF-8 representation is used as input for the fingerprint
        Returns:
        The fingerprint - null if null/empty input
        Throws:
        java.lang.Exception - If failed to calculate the digest
        See Also:
        getFingerPrint(Digest, String, Charset)
      • getFingerPrint

        public static java.lang.String getFingerPrint​(Digest d,
                                                      java.lang.String s,
                                                      java.nio.charset.Charset charset)
                                               throws java.lang.Exception
        Parameters:
        d - The Digest to use
        s - The String to digest - ignored if null/empty
        charset - The Charset to use in order to convert the string to its byte representation to use as input for the fingerprint
        Returns:
        The fingerprint - null if null/empty input
        Throws:
        java.lang.Exception - If failed to calculate the digest
      • getFingerPrint

        public static java.lang.String getFingerPrint​(Factory<? extends Digest> f,
                                                      byte... buf)
                                               throws java.lang.Exception
        Parameters:
        f - The Factory to create the Digest to use
        buf - The data buffer to be fingerprint-ed
        Returns:
        The fingerprint - null if empty data buffer
        Throws:
        java.lang.Exception - If failed to calculate the fingerprint
        See Also:
        getFingerPrint(Factory, byte[], int, int)
      • getFingerPrint

        public static java.lang.String getFingerPrint​(Factory<? extends Digest> f,
                                                      byte[] buf,
                                                      int offset,
                                                      int len)
                                               throws java.lang.Exception
        Parameters:
        f - The Factory to create the Digest to use
        buf - The data buffer to be fingerprint-ed
        offset - The offset of the data in the buffer
        len - The length of data - ignored if non-positive
        Returns:
        The fingerprint - null if non-positive length
        Throws:
        java.lang.Exception - If failed to calculate the fingerprint
      • getFingerPrint

        public static java.lang.String getFingerPrint​(Digest d,
                                                      byte... buf)
                                               throws java.lang.Exception
        Parameters:
        d - The Digest to use
        buf - The data buffer to be fingerprint-ed
        Returns:
        The fingerprint - null if empty data buffer
        Throws:
        java.lang.Exception - If failed to calculate the fingerprint
        See Also:
        getFingerPrint(Digest, byte[], int, int)
      • getFingerPrint

        public static java.lang.String getFingerPrint​(Digest d,
                                                      byte[] buf,
                                                      int offset,
                                                      int len)
                                               throws java.lang.Exception
        Parameters:
        d - The Digest to use
        buf - The data buffer to be fingerprint-ed
        offset - The offset of the data in the buffer
        len - The length of data - ignored if non-positive
        Returns:
        The fingerprint - null if non-positive length
        Throws:
        java.lang.Exception - If failed to calculate the fingerprint
        See Also:
        getRawFingerprint(Digest, byte[], int, int)
      • getRawFingerprint

        public static byte[] getRawFingerprint​(Digest d,
                                               byte... buf)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getRawFingerprint

        public static byte[] getRawFingerprint​(Digest d,
                                               byte[] buf,
                                               int offset,
                                               int len)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception