-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update BfCrypt.cpp #2
Open
Seltraeh
wants to merge
3
commits into
decompfrontier:main
Choose a base branch
from
Seltraeh:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
#include "BfCrypt.hpp" | ||
|
||
#include <json/json.h> | ||
|
||
#include <trantor/utils/Logger.h> | ||
|
||
#include <cryptopp/aes.h> | ||
#include <cryptopp/modes.h> | ||
#include <cryptopp/filters.h> | ||
|
||
#include <drogon/utils/Utilities.h> | ||
|
||
using namespace std; | ||
using namespace BfCrypt; // for CryptSREE, CryptGME, and DecryptGME | ||
using namespace CryptoPP; // for aes, modes, and filters | ||
|
||
static const unsigned char SREE_KEY[] = { 0x37, 0x34, 0x31, 0x30, 0x39, 0x35, 0x38, 0x31, 0x36, 0x34, 0x33, 0x35, 0x34, 0x38, 0x37, 0x31 }; // 7410958164354871 | ||
static const unsigned char SREE_IV[] = { 0x42, 0x66, 0x77, 0x34, 0x65, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x65, 0x64, 0x50, 0x61, 0x73, 0x73 }; // Bfw4encrypedPass | ||
|
||
using namespace CryptoPP; | ||
|
||
std::string BfCrypt::CryptSREE(const Json::Value& v) | ||
string CryptSREE(const Json::Value& v) | ||
{ | ||
try | ||
{ | ||
|
@@ -30,7 +28,7 @@ std::string BfCrypt::CryptSREE(const Json::Value& v) | |
for (int i = 0; i < (AES::BLOCKSIZE - p); i++) | ||
str += " "; | ||
|
||
std::string tmp = "", output = ""; | ||
string tmp = "", output = ""; | ||
|
||
CBC_Mode<AES>::Encryption e; | ||
e.SetKeyWithIV(SREE_KEY, sizeof(SREE_KEY), SREE_IV); | ||
|
@@ -46,7 +44,7 @@ std::string BfCrypt::CryptSREE(const Json::Value& v) | |
} | ||
} | ||
|
||
std::string BfCrypt::CryptGME(const Json::Value& v, const std::string& key) | ||
string CryptGME(const Json::Value& v, const string& key) | ||
{ | ||
try | ||
{ | ||
|
@@ -61,13 +59,13 @@ std::string BfCrypt::CryptGME(const Json::Value& v, const std::string& key) | |
byte aeskey[AES::MIN_KEYLENGTH] = { 0x00 }; | ||
// keys are setted this way because we know that some keys might not have the minimum requirement | ||
#ifdef _MSC_VER | ||
memcpy_s(aeskey, _countof(aeskey), key.data(), std::min(key.size(), (size_t)sizeof(aeskey))); | ||
memcpy_s(aeskey, _countof(aeskey), key.data(), min(key.size(), (size_t)sizeof(aeskey))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember a compilation error might happend on Windows unless NOMINMAX is defined, is this code buildable with MSVC + Windows? |
||
#else | ||
memcpy(aeskey, key.data(), std::min(key.size(), (size_t)sizeof(aeskey))); | ||
memcpy(aeskey, key.data(), min(key.size(), (size_t)sizeof(aeskey))); | ||
#endif | ||
e.SetKey(aeskey, sizeof(aeskey)); | ||
|
||
std::string tmp; | ||
string tmp; | ||
StringSource ss(str, true, new StreamTransformationFilter(e, new StringSink(tmp), StreamTransformationFilter::PKCS_PADDING)); | ||
|
||
return drogon::utils::base64Encode((const unsigned char*)tmp.data(), tmp.size()); | ||
|
@@ -79,25 +77,25 @@ std::string BfCrypt::CryptGME(const Json::Value& v, const std::string& key) | |
} | ||
} | ||
|
||
void BfCrypt::DecryptGME(const std::string& in, const std::string& key, Json::Value& v) | ||
void DecryptGME(const string& in, const string& key, Json::Value& v) | ||
{ | ||
if (key.empty() || in.empty()) | ||
return; | ||
|
||
try | ||
{ | ||
std::string tmp = drogon::utils::base64Decode(in); | ||
string tmp = drogon::utils::base64Decode(in); | ||
|
||
ECB_Mode<AES>::Decryption e; | ||
byte aeskey[AES::MIN_KEYLENGTH] = { 0x00 }; | ||
#ifdef _MSC_VER | ||
memcpy_s(aeskey, _countof(aeskey), key.data(), std::min(key.size(), (size_t)sizeof(aeskey))); | ||
memcpy_s(aeskey, _countof(aeskey), key.data(), min(key.size(), (size_t)sizeof(aeskey))); | ||
#else | ||
memcpy(aeskey, key.data(), std::min(key.size(), (size_t)sizeof(aeskey))); | ||
memcpy(aeskey, key.data(), min(key.size(), (size_t)sizeof(aeskey))); | ||
#endif | ||
e.SetKey(aeskey, sizeof(aeskey)); | ||
|
||
std::string output; | ||
string output; | ||
StringSource ss(tmp, true, | ||
new StreamTransformationFilter(e, | ||
new StringSink(output) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think automatilly setting the namespace for CryptSREE would make the function think it's not part of a class rather part of function outside of any namespace