| 56 | |
| 57 | |
| 58 | DWORD EncryptString(const unsigned char* lpData, const char* lpKey, unsigned char*& lpOut, DWORD dwDataSize) |
| 59 | { |
| 60 | unsigned char btBlock[16]; |
| 61 | unsigned char btKey[16]; |
| 62 | unsigned int dwOutLen = 0; |
| 63 | unsigned int iMul = 0; |
| 64 | |
| 65 | if ((dwDataSize % 16)) |
| 66 | iMul = 1; |
| 67 | |
| 68 | dwOutLen = ((dwDataSize / 16) + iMul) * 16; |
| 69 | |
| 70 | lpOut = (unsigned char*)malloc(dwOutLen + 1); |
| 71 | |
| 72 | memset(lpOut, 0x00, dwOutLen + 1); |
| 73 | |
| 74 | memset(btKey, 0x00, 16); |
| 75 | |
| 76 | memcpy(btKey, lpKey, strlen(lpKey) > 16 ? 16 : strlen(lpKey)); |
| 77 | |
| 78 | for (int i = 0; i * 16 < dwDataSize; ++i) { |
| 79 | |
| 80 | unsigned int uiBlockSize = 16; |
| 81 | |
| 82 | if ((dwDataSize - (i * 16)) < 16) |
| 83 | uiBlockSize = (dwDataSize - (i * 16)); |
| 84 | |
| 85 | memset(btBlock, 0x00, 16); |
| 86 | memcpy(btBlock, lpData + (i * 16), uiBlockSize); |
| 87 | |
| 88 | AES_ECB_encrypt(lpData + (i * 16), btKey, lpOut + (i * 16), 16); |
| 89 | } |
| 90 | |
| 91 | return dwOutLen; |
| 92 | } |
| 93 | |
| 94 | DWORD DecryptString(const unsigned char* lpData, const char* lpKey, unsigned char*& lpOut, DWORD dwDataSize) |
| 95 | { |
no test coverage detected