本文整理汇总了C++中Crypto::Decrypt方法的典型用法代码示例。如果您正苦于以下问题:C++ Crypto::Decrypt方法的具体用法?C++ Crypto::Decrypt怎么用?C++ Crypto::Decrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypto
的用法示例。
在下文中一共展示了Crypto::Decrypt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestEncryptDecrypt
static int TestEncryptDecrypt(const Crypto& cryptoA, const Crypto& cryptoB)
{
std::string content= cryptoA.GeneratePassword(std::string("0123456789abcdefghijklmnopqrstuvABCDEFGHIJKLMNOPQRSTUVWXYZ"), 256000);
auto encrypted = cryptoA.Encrypt(std::vector<BYTE>(content.begin(), content.end()), true);
auto decrypted = cryptoB.Decrypt(encrypted, true);
auto sameCount = 0;
for (auto index = 0 ; index != content.length() ; ++index)
{
sameCount += content[index] == encrypted[index] ? 1 : 0;
if (content[index] != decrypted[index])
{
std::wcout << L"Crypto::Encrypt decrypted content error" << std::endl;
return 1;
}
}
if (sameCount == content.length())
{
std::wcout << L"Crypto::Encrypt encrypted content error" << std::endl;
return 1;
}
return 0;
}
示例2: sizeof
// Our thread to handle incoming packets
void *recv_thread( void *arg ) {
int s = *(int*) arg;
struct sockaddr_in si_other;
socklen_t slen = sizeof( si_other );
int ret;
unsigned char buffer[512];
Crypto crypto;
while( !exit_bot ) {
ret = recvfrom( s, buffer, 512, 0, (struct sockaddr*)&si_other, &slen );
if( ret == -1 ) {
printf( "Recvfrom error\n" );
return 0;
}
//printf( "Length of packet: %i\n", ret );
//printf( "Received packet from %s:%d\n", inet_ntoa( si_other.sin_addr ), ntohs( si_other.sin_port ));
crypto.Decrypt( buffer, ret );
//printf( "recveived packet: " );
//for( int i = 0; i < ret; i++ ) {
// printf( "%02X ", buffer[ i ] );
//}
//printf( "\n" );
if( buffer[0] == 0x25 ) { // Ping Response
ping_success = true;
} else if( buffer[0] == 0x0F ) {
login_success = true;
// Get the player id for the first player
player_id = *(uint16*)&buffer[41]; //1 = first, 41 = second
printf( "[%s] Player ID: %i\n", currentDateTime().c_str(), player_id );
} else if( buffer[0] == 0x1F ) { // Enter world response
InitialLoginData ild = *(InitialLoginData*)&buffer[1];
printf( "X/Y: %i, %i | MapID: %i | Player ID: %i\n ", ild.positionX, ild.positionY, ild.mapId, ild.serverId );
loggedin = true;
} else if( buffer[0] == 0x03 ) { // Update packet
handleUpdatePacket( buffer, ret );
} else if( buffer[0] == 0x1e ) { // Quest Log
QuestLog q = *(QuestLog*)&buffer[1];
if( q.curkills == q.reqkills || q.curkills == 100 ) {
finished_quest = true;
}
if( q.curquest != 87 ) {
finished_quest = true;
missing_quest = true;
} else {
have_quest = true;
}
lastQL = q;
printf( "[%s] QuestLog Requested: %i kills of %i\n", currentDateTime().c_str(), q.curkills, q.reqkills );
} else if( buffer[0] == 0x0C ) { // Logout and misc?
if( buffer[1] == 0x15 ) { // Logout
login_success = false;
loggedin = false;
finished_quest = true;
missing_quest = true;
printf( "[%s] Player has logged out\n", currentDateTime().c_str());
} else {
//printf( "[%s] Recived 0x0C Packet Type\n", currentDateTime().c_str());
//FILE *o = fopen( "in-packets.log", "a+" );
//for( int i = 0; i < ret; i++ ) {
// fprintf( o, "%02X ", buffer[ i ] );
//}
//fprintf( o, "\n" );
//fclose( o );
}
}
}
return 0;
}