-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrsa.cpp
More file actions
29 lines (26 loc) · 754 Bytes
/
rsa.cpp
File metadata and controls
29 lines (26 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "stdafx.h"
#include "rsa.h"
#include "debug.h"
bool rsaCryptBE(HCRYPTKEY key, BYTE * data, DWORD dataSize, BYTE ** dataOut, DWORD * dataOutSize)
{
*dataOutSize = dataSize;
if (!CryptEncrypt(key, 0, TRUE, 0, NULL, dataOutSize, 0))
{
WDEBUG("Could not rsa botId : " << GetLastError());
return false;
}
*dataOut = new BYTE[*dataOutSize];
memcpy_s(*dataOut, *dataOutSize, data, dataSize);
if (!CryptEncrypt(key, 0, TRUE, 0, *dataOut, &dataSize, *dataOutSize))
{
WDEBUG("Could not rsa botId : " << GetLastError());
return false;
}
for (unsigned int i = 0; i < (*dataOutSize / 2); i++)
{
BYTE c = (*dataOut)[i];
(*dataOut)[i] = (*dataOut)[(*dataOutSize) - 1 - i];
(*dataOut)[(*dataOutSize) - 1 - i] = c;
}
return true;
}