Package ghidra.util

Class HashUtilities

java.lang.Object
ghidra.util.HashUtilities

public class HashUtilities extends Object
  • Field Details

    • MD5_ALGORITHM

      public static String MD5_ALGORITHM
    • SHA256_ALGORITHM

      public static String SHA256_ALGORITHM
    • SALT_LENGTH

      public static final int SALT_LENGTH
      See Also:
    • MD5_UNSALTED_HASH_LENGTH

      public static final int MD5_UNSALTED_HASH_LENGTH
      See Also:
    • MD5_SALTED_HASH_LENGTH

      public static final int MD5_SALTED_HASH_LENGTH
      See Also:
    • SHA256_UNSALTED_HASH_LENGTH

      public static final int SHA256_UNSALTED_HASH_LENGTH
      See Also:
    • SHA256_SALTED_HASH_LENGTH

      public static final int SHA256_SALTED_HASH_LENGTH
      See Also:
  • Constructor Details

    • HashUtilities

      public HashUtilities()
  • Method Details

    • getHash

      public static char[] getHash(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:
      IllegalArgumentException - if specified algorithm is not supported
      See Also:
    • getSaltedHash

      public static char[] getSaltedHash(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:
      IllegalArgumentException - if specified algorithm is not supported
      See Also:
    • getSaltedHash

      public static char[] getSaltedHash(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:
      IllegalArgumentException - if specified algorithm is not supported
      See Also:
    • getHash

      public static String getHash(String algorithm, InputStream in) throws 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:
      IOException - if reading input stream produces an error
      IllegalArgumentException - if specified algorithm is not supported
      See Also:
    • getHash

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

      public static String getHash(String algorithm, List<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:
      IllegalArgumentException - if specified algorithm is not supported
      See Also:
    • getHash

      public static String getHash(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:
      IllegalArgumentException - if specified algorithm is not supported
      See Also:
    • 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