| 284 | } |
| 285 | |
| 286 | DWORD EncryptString(const unsigned char* lpData, const char* lpKey, unsigned char*& lpOut, DWORD dwDataSize) |
| 287 | { |
| 288 | unsigned char btBlock[16]; |
| 289 | unsigned char btKey[16]; |
| 290 | unsigned int dwOutLen = 0; |
| 291 | unsigned int iMul = 0; |
| 292 | |
| 293 | if ((dwDataSize % 16)) |
| 294 | iMul = 1; |
| 295 | |
| 296 | dwOutLen = ((dwDataSize / 16) + iMul) * 16; |
| 297 | |
| 298 | lpOut = (unsigned char*)malloc(dwOutLen + 1); |
| 299 | |
| 300 | memset(lpOut, 0x00, dwOutLen + 1); |
| 301 | |
| 302 | memset(btKey, 0x00, 16); |
| 303 | |
| 304 | memcpy(btKey, lpKey, strlen(lpKey) > 16 ? 16 : strlen(lpKey)); |
| 305 | |
| 306 | for (int i = 0; i * 16 < dwDataSize; ++i) { |
| 307 | |
| 308 | unsigned int uiBlockSize = 16; |
| 309 | |
| 310 | if ((dwDataSize - (i * 16)) < 16) |
| 311 | uiBlockSize = (dwDataSize - (i * 16)); |
| 312 | |
| 313 | memset(btBlock, 0x00, 16); |
| 314 | memcpy(btBlock, lpData + (i * 16), uiBlockSize); |
| 315 | |
| 316 | AES_ECB_encrypt(lpData + (i * 16), btKey, lpOut + (i * 16), 16); |
| 317 | } |
| 318 | |
| 319 | return dwOutLen; |
| 320 | } |
| 321 | |
| 322 | DWORD DecryptString(const unsigned char* lpData, const char* lpKey, unsigned char*& lpOut, DWORD dwDataSize) |
| 323 | { |
no test coverage detected