File Hashing¶
-
file_hashing.convert_string_to_binary(string)¶ This function attempts to convert a string to binary.
Acknowledgments: Thanks to Minnie Kumar for finding an error in the get_hash_of_string function and providing a solution.
Code based an answer from Elizafox on Stack Overflow: http://stackoverflow.com/questions/34869889/what-is-the-proper-way-to-determine-if-an-object-is-a-bytes-like-object-in-pytho
-
file_hashing.do_files_have_same_content(file_1, file_2, algorithm='MD5')¶ This function checks the hashes of the contents of two files. It returns a boolean.
Acknowledgments: Thanks to Ryan Dorrien and Kyle O’Neill for working on this function.
-
file_hashing.get_hash_of_binary_file_contents(file_path, algorithm='MD5')¶ This function will read and hash the contents of a file.
Parameters: - file_path (str.) – The path to the file to be hashed.
- algorithm (str.) – The hashing algorithm to be used. Defaults to ‘MD5’.
Returns: str – The hash of the contents of the file.
-
file_hashing.get_hash_of_string(string, algorithm='MD5')¶ This function takes a string and hashes it using an algorithm.
Acknowledgments: Addition of multiple hashing algorithms courtesy of Anthony Capece, Elvis Gadtaula, Nick Parenti, Jordan Polun, and Christopher Tafel. Dictionary and associated functionality is courtesy of Jordan Polun. Documentation is courtesy of Jazlin Perez and Jordan Polun.
Parameters: - string (str.) – this is the string that will be hashed.
- algorithm (str.) – The hashing algorithm to be used. Defaults to ‘MD5’.
Returns: str – The hash of the string.
-
file_hashing.get_hashes_of_files_in_directory(directory, algorithm='MD5')¶ This function will get the hashes of all files in a directory.
Acknowledgments: This function is courtesy of Minnie Kumar, Kyle O’Neill, Lawrence Rosenstadt, and Tiffany Xu.
-
file_hashing.read_binary_file(file_path)¶ This function will read and hash the contents of a file.
Acknowledgments: Documentation is courtesy of Jazlin Perez and Jordan Polun. Thanks to Joseph Darocha for fixing the return error.
Parameters: file_path (str.) – this is the path to the file to be read. Returns: str – the content of the file to be read