Created
May 9, 2023 00:44
-
-
Save RomanRobot/c3f6bdbf58ee24036586ed67c5218c55 to your computer and use it in GitHub Desktop.
Calculate MD5 of a file in Unreal Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FString MD5(FString file_name) | |
{ | |
std::ifstream file(std::string(TCHAR_TO_UTF8(*file_name)), std::ios::binary); | |
if (!file) { | |
return FString(); | |
} | |
// Compute the MD5 hash of the file contents | |
FMD5 md5; | |
char buffer[4096]; | |
while (file.read(buffer, sizeof(buffer))) { | |
md5.Update((const uint8*)buffer, sizeof(buffer)); | |
} | |
md5.Update((const uint8*)buffer, file.gcount()); | |
uint8 hash[16]; | |
md5.Final(hash); | |
// Convert the hash value to a string of hexadecimal digits | |
FString string = FString::Printf(TEXT("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"), | |
hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7], | |
hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15]); | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment