Class DigestUtils

    • Method Detail

      • checkSupported

        public static boolean checkSupported​(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​(String algo,
                                                                 Comparator<? super String> comp,
                                                                 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​(String algo,
                                                                         Comparator<? super String> comp,
                                                                         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 String getFingerPrint​(Factory<? extends Digest> f,
                                            String s,
                                            Charset charset)
                                     throws 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:
        Exception - If failed to calculate the digest
      • getFingerPrint

        public static String getFingerPrint​(Digest d,
                                            String s,
                                            Charset charset)
                                     throws 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:
        Exception - If failed to calculate the digest
      • getFingerPrint

        public static String getFingerPrint​(Factory<? extends Digest> f,
                                            byte[] buf,
                                            int offset,
                                            int len)
                                     throws 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:
        Exception - If failed to calculate the fingerprint
      • getFingerPrint

        public static String getFingerPrint​(Digest d,
                                            byte[] buf,
                                            int offset,
                                            int len)
                                     throws 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:
        Exception - If failed to calculate the fingerprint
        See Also:
        getRawFingerprint(Digest, byte[], int, int)
      • getRawFingerprint

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

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