Package ghidra.util
Class HashUtilities
- java.lang.Object
-
- ghidra.util.HashUtilities
-
public class HashUtilities extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
MD5_ALGORITHM
static int
MD5_SALTED_HASH_LENGTH
static int
MD5_UNSALTED_HASH_LENGTH
static int
SALT_LENGTH
static java.lang.String
SHA256_ALGORITHM
static int
SHA256_SALTED_HASH_LENGTH
static int
SHA256_UNSALTED_HASH_LENGTH
-
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 representationstatic 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.
-
-
-
Field Detail
-
MD5_ALGORITHM
public static java.lang.String MD5_ALGORITHM
-
SHA256_ALGORITHM
public static java.lang.String SHA256_ALGORITHM
-
SALT_LENGTH
public static final int SALT_LENGTH
- See Also:
- Constant Field Values
-
MD5_UNSALTED_HASH_LENGTH
public static final int MD5_UNSALTED_HASH_LENGTH
- See Also:
- Constant Field Values
-
MD5_SALTED_HASH_LENGTH
public static final int MD5_SALTED_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
-
-
Method Detail
-
getHash
public static char[] getHash(java.lang.String algorithm, char[] msg)
Generate hash in a hex character representation- Parameters:
algorithm
- message digest algorithmmsg
- 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 algorithmsalt
- 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 algorithmmsg
- 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 algorithmin
- input stream- Returns:
- message digest hash
- Throws:
java.io.IOException
- if reading input stream produces an errorjava.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 algorithmfile
- file to be read- Returns:
- message digest hash
- Throws:
java.io.IOException
- if opening or reading file produces an errorjava.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 algorithmvalues
- 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 algorithmvalues
- 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
-
-