safer Crypt initializer
This commit is contained in:
parent
c2b3e6b0e8
commit
b5dd095f27
|
|
@ -4,7 +4,6 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "Hooks/Crypt.h"
|
#include "Hooks/Crypt.h"
|
||||||
|
|
||||||
|
|
||||||
Crypt::Crypt()
|
Crypt::Crypt()
|
||||||
{
|
{
|
||||||
if (!CryptAcquireContext(&context, NULL, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, CRYPT_VERIFYCONTEXT))
|
if (!CryptAcquireContext(&context, NULL, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, CRYPT_VERIFYCONTEXT))
|
||||||
|
|
@ -22,18 +21,29 @@ Crypt::Crypt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
std::vector<BYTE> publicKey = Util::base64Decode(Util::publicKey);
|
std::vector<BYTE> publicKey = Util::base64Decode(Util::publicKey);
|
||||||
#else
|
#else
|
||||||
std::vector<BYTE> publicKey = Util::publicKey;
|
std::vector<BYTE> publicKey = Util::publicKey;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BYTE* blob = new BYTE[publicKey.size()];
|
BYTE* blob = new BYTE[publicKey.size()];
|
||||||
std::copy(publicKey.begin(), publicKey.end(), blob);
|
std::copy(publicKey.begin(), publicKey.end(), blob);
|
||||||
|
|
||||||
if (!CryptImportKey(context, blob, publicKey.size(), 0, 0, &key))
|
if (!CryptImportKey(context, blob, publicKey.size(), 0, 0, &key))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
{
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
|
throw std::runtime_error("Failed to import public key");
|
||||||
|
#else
|
||||||
throw std::runtime_error("Error during CryptImportKey");
|
throw std::runtime_error("Error during CryptImportKey");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue