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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
std::vector<std::string> Decrypt(sqlite3_stmt * stmt,int column)
{
LPWSTR str = NULL;
std::vector<std::string> data;
std::string tmp;
DATA_BLOB in,out;
memset(&in,0,sizeof(in));
memset(&out,0,sizeof(out));
try
{
while(sqlite3_step(stmt) == SQLITE_ROW)
{
in.cbData = sqlite3_column_bytes(stmt,column);
in.pbData = (BYTE *)sqlite3_column_blob(stmt,column);
if(!CryptUnprotectData(&in,&str,NULL,NULL,NULL,0,&out))
{
throw chrome::Event::Err(GetLastError());
}
tmp = reinterpret_cast<char*>(out.pbData);
data.push_back(tmp);
std::cout << ".";
}
return data;
}
catch(chrome::Event::Err& exc)
{
std::cerr << "CryptUnprotectData() fail " << GetLastError() << std::endl;
LocalFree(str);
LocalFree(&in);
LocalFree(&out);
data.at(0) = "ERROR";
return data;
}
}
| |