mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-06-28 05:05:38 +00:00
fix(hasher): USE OPENSSL
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
#include "stdafx.h"
|
||||
#if defined(_WIN32)
|
||||
#include <xhash>
|
||||
|
||||
#else
|
||||
#include <openssl/md5.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#endif // _WIN32
|
||||
#include "Hasher.h"
|
||||
|
||||
Hasher::Hasher(wstring &salt)
|
||||
@@ -10,6 +16,7 @@ Hasher::Hasher(wstring &salt)
|
||||
|
||||
wstring Hasher::getHash(wstring &name)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
// 4J Stu - Removed try/catch
|
||||
//try {
|
||||
wstring s = wstring( salt ).append( name );
|
||||
@@ -25,4 +32,21 @@ wstring Hasher::getHash(wstring &name)
|
||||
//{
|
||||
// throw new RuntimeException(e);
|
||||
//}
|
||||
}
|
||||
#else
|
||||
// adapted from a SSL example
|
||||
std::wstring combined = salt + name;
|
||||
std::string combined_str(combined.begin(), combined.end());
|
||||
unsigned char result[MD5_DIGEST_LENGTH];
|
||||
MD5_CTX md5_ctx;
|
||||
MD5_Init(&md5_ctx);
|
||||
MD5_Update(&md5_ctx, combined_str.c_str(), combined_str.size());
|
||||
MD5_Final(result, &md5_ctx);
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i < MD5_DIGEST_LENGTH; i++)
|
||||
{
|
||||
ss << std::setw(2) << std::setfill('0') << std::hex << (int)result[i];
|
||||
}
|
||||
std::string hash_str = ss.str();
|
||||
return std::wstring(hash_str.begin(), hash_str.end());
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user