mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
More SHA encoding functions and add missing copyright
This commit is contained in:
@@ -178,7 +178,7 @@ std::string Crypt::decrypt(const std::string& encrypted_string)
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string Crypt::md5Encode(std::string decoded_string, bool upperCase)
|
||||
std::string Crypt::md5Encode(const std::string& decoded_string, bool upperCase)
|
||||
{
|
||||
MD5_CTX c;
|
||||
MD5_Init(&c);
|
||||
@@ -199,7 +199,7 @@ std::string Crypt::md5Encode(std::string decoded_string, bool upperCase)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Crypt::sha1Encode(std::string decoded_string, bool upperCase)
|
||||
std::string Crypt::sha1Encode(const std::string& decoded_string, bool upperCase)
|
||||
{
|
||||
SHA_CTX c;
|
||||
SHA1_Init(&c);
|
||||
@@ -220,6 +220,48 @@ std::string Crypt::sha1Encode(std::string decoded_string, bool upperCase)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Crypt::sha256Encode(const std::string& decoded_string, bool upperCase)
|
||||
{
|
||||
SHA256_CTX c;
|
||||
SHA256_Init(&c);
|
||||
SHA256_Update(&c, decoded_string.c_str(), decoded_string.length());
|
||||
|
||||
uint8_t md[SHA256_DIGEST_LENGTH];
|
||||
SHA256_Final(md, &c);
|
||||
|
||||
char output[(SHA256_DIGEST_LENGTH << 1) + 1];
|
||||
for(int32_t i = 0; i < (int32_t)sizeof(md); ++i)
|
||||
sprintf(output + (i << 1), "%.2X", md[i]);
|
||||
|
||||
std::string result = output;
|
||||
if(upperCase)
|
||||
return result;
|
||||
|
||||
std::transform(result.begin(), result.end(), result.begin(), tolower);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Crypt::sha512Encode(const std::string& decoded_string, bool upperCase)
|
||||
{
|
||||
SHA512_CTX c;
|
||||
SHA512_Init(&c);
|
||||
SHA512_Update(&c, decoded_string.c_str(), decoded_string.length());
|
||||
|
||||
uint8_t md[SHA512_DIGEST_LENGTH];
|
||||
SHA512_Final(md, &c);
|
||||
|
||||
char output[(SHA512_DIGEST_LENGTH << 1) + 1];
|
||||
for(int32_t i = 0; i < (int32_t)sizeof(md); ++i)
|
||||
sprintf(output + (i << 1), "%.2X", md[i]);
|
||||
|
||||
std::string result = output;
|
||||
if(upperCase)
|
||||
return result;
|
||||
|
||||
std::transform(result.begin(), result.end(), result.begin(), tolower);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Crypt::rsaSetPublicKey(const std::string& n, const std::string& e)
|
||||
{
|
||||
BN_dec2bn(&m_rsa->n, n.c_str());
|
||||
|
@@ -40,8 +40,10 @@ public:
|
||||
std::string genUUIDKey();
|
||||
std::string encrypt(const std::string& decrypted_string);
|
||||
std::string decrypt(const std::string& encrypted_string);
|
||||
std::string md5Encode(std::string decoded_string, bool upperCase);
|
||||
std::string sha1Encode(std::string decoded_string, bool upperCase);
|
||||
std::string md5Encode(const std::string& decoded_string, bool upperCase);
|
||||
std::string sha1Encode(const std::string& decoded_string, bool upperCase);
|
||||
std::string sha256Encode(const std::string& decoded_string, bool upperCase);
|
||||
std::string sha512Encode(const std::string& decoded_string, bool upperCase);
|
||||
|
||||
void rsaSetPublicKey(const std::string& n, const std::string& e);
|
||||
void rsaSetPrivateKey(const std::string &p, const std::string &q, const std::string &d);
|
||||
|
Reference in New Issue
Block a user