Package ghidra.util

Class HashUtilities


  • public class HashUtilities
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      HashUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getHash​(java.lang.String algorithm, byte[] values)
      Generate combined message digest hash for the bytes in the specified array.
      static char[] getHash​(java.lang.String algorithm, char[] msg)
      Generate hash in a hex character representation
      static java.lang.String getHash​(java.lang.String algorithm, java.io.File file)
      Generate message digest hash for specified file contents.
      static java.lang.String getHash​(java.lang.String algorithm, java.io.InputStream in)
      Generate message digest hash for specified input stream.
      static java.lang.String getHash​(java.lang.String algorithm, java.util.List<java.lang.String> values)
      Generate combined message digest hash for all values in the specified values list.
      static char[] getSaltedHash​(java.lang.String algorithm, char[] msg)
      Generate salted hash for specified message using random salt.
      static char[] getSaltedHash​(java.lang.String algorithm, char[] salt, char[] msg)
      Generate salted hash for specified message.
      static char[] hexDump​(byte[] data)
      Convert binary data to a sequence of hex characters.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MD5_ALGORITHM

        public static java.lang.String MD5_ALGORITHM
      • SHA256_ALGORITHM

        public static java.lang.String SHA256_ALGORITHM
      • MD5_UNSALTED_HASH_LENGTH

        public static final int MD5_UNSALTED_HASH_LENGTH
        See Also:
        Constant Field Values
      • SHA256_UNSALTED_HASH_LENGTH

        public static final int SHA256_UNSALTED_HASH_LENGTH
        See Also:
        Constant Field Values
      • SHA256_SALTED_HASH_LENGTH

        public static final int SHA256_SALTED_HASH_LENGTH
        See Also:
        Constant Field Values
    • Constructor Detail

      • HashUtilities

        public HashUtilities()
    • Method Detail

      • getHash

        public static char[] getHash​(java.lang.String algorithm,
                                     char[] msg)
        Generate hash in a hex character representation
        Parameters:
        algorithm - message digest algorithm
        msg - message text
        Returns:
        hex hash value in text format
        Throws:
        java.lang.IllegalArgumentException - if specified algorithm is not supported
        See Also:
        for supported algorithms
      • getSaltedHash

        public static char[] getSaltedHash​(java.lang.String algorithm,
                                           char[] salt,
                                           char[] msg)
        Generate salted hash for specified message. Supplied salt is returned as prefix to returned hash.
        Parameters:
        algorithm - message digest algorithm
        salt - digest salt (use empty string for no salt)
        msg - message text
        Returns:
        salted hash using specified salt which is returned as a prefix to the hash
        Throws:
        java.lang.IllegalArgumentException - if specified algorithm is not supported
        See Also:
        for supported hash algorithms
      • getSaltedHash

        public static char[] getSaltedHash​(java.lang.String algorithm,
                                           char[] msg)
        Generate salted hash for specified message using random salt. First 4-characters of returned hash correspond to the salt data.
        Parameters:
        algorithm - message digest algorithm
        msg - message text
        Returns:
        salted hash using randomly generated salt which is returned as a prefix to the hash
        Throws:
        java.lang.IllegalArgumentException - if specified algorithm is not supported
        See Also:
        for supported hash algorithms
      • getHash

        public static java.lang.String getHash​(java.lang.String algorithm,
                                               java.io.InputStream in)
                                        throws java.io.IOException
        Generate message digest hash for specified input stream. Stream will be read until EOF is reached.
        Parameters:
        algorithm - message digest algorithm
        in - input stream
        Returns:
        message digest hash
        Throws:
        java.io.IOException - if reading input stream produces an error
        java.lang.IllegalArgumentException - if specified algorithm is not supported
        See Also:
        for supported hash algorithms
      • getHash

        public static java.lang.String getHash​(java.lang.String algorithm,
                                               java.io.File file)
                                        throws java.io.IOException
        Generate message digest hash for specified file contents.
        Parameters:
        algorithm - message digest algorithm
        file - file to be read
        Returns:
        message digest hash
        Throws:
        java.io.IOException - if opening or reading file produces an error
        java.lang.IllegalArgumentException - if specified algorithm is not supported
        See Also:
        for supported hash algorithms
      • getHash

        public static java.lang.String getHash​(java.lang.String algorithm,
                                               java.util.List<java.lang.String> values)
        Generate combined message digest hash for all values in the specified values list.
        Parameters:
        algorithm - message digest algorithm
        values - list of text strings
        Returns:
        message digest hash
        Throws:
        java.lang.IllegalArgumentException - if specified algorithm is not supported
        See Also:
        for supported hash algorithms
      • getHash

        public static java.lang.String getHash​(java.lang.String algorithm,
                                               byte[] values)
        Generate combined message digest hash for the bytes in the specified array.
        Parameters:
        algorithm - message digest algorithm
        values - array of bytes to hash
        Returns:
        message digest hash
        Throws:
        java.lang.IllegalArgumentException - if specified algorithm is not supported
        See Also:
        for supported hash algorithms
      • hexDump

        public static char[] hexDump​(byte[] data)
        Convert binary data to a sequence of hex characters.
        Parameters:
        data - binary data
        Returns:
        hex character representation of data