MCPcopy Create free account
hub / github.com/bruderstein/nppPluginManager / decrypt

Method decrypt

pluginManager/src/Encrypter.cpp:69–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67
68
69int Encrypter::decrypt(const unsigned char *encKeyBuffer, const int encKeyLength, unsigned char *keyBuffer, const int keyLength)
70{
71 int retVal = 0;
72
73 DATA_BLOB pDataOut;
74 DATA_BLOB pDataIn;
75 pDataIn.cbData = encKeyLength;
76 pDataIn.pbData = static_cast<BYTE *>(const_cast<unsigned char *>(encKeyBuffer));
77
78 HMODULE crypt32 = LoadLibrary(_T("crypt32.dll"));
79
80 if (crypt32 != NULL)
81 {
82 typedef BOOL (__stdcall * CryptUnprotectDataFunc)(DATA_BLOB*, LPCTSTR, DATA_BLOB*, PVOID, CRYPTPROTECT_PROMPTSTRUCT*, DWORD, DATA_BLOB*);
83 CryptUnprotectDataFunc cryptUnprotectData;
84 cryptUnprotectData = (CryptUnprotectDataFunc)GetProcAddress(crypt32, "CryptUnprotectData");
85 if (NULL != cryptUnprotectData)
86 {
87 BOOL success = cryptUnprotectData(&pDataIn, NULL, NULL, NULL, NULL, NULL, &pDataOut);
88
89 if (success && (keyLength >= static_cast<int>(pDataOut.cbData)))
90 {
91 memcpy(keyBuffer, pDataOut.pbData, pDataOut.cbData);
92 retVal = pDataOut.cbData;
93 }
94 LocalFree(pDataOut.pbData);
95 }
96
97 }
98
99 return retVal;
100}
101
102
103int Encrypter::decryptHex(const TCHAR *encrypted, unsigned char *decryptBuffer, const int bufferLength)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected