当前位置: 首页>>代码示例>>C++>>正文


C++ Crypto类代码示例

本文整理汇总了C++中Crypto的典型用法代码示例。如果您正苦于以下问题:C++ Crypto类的具体用法?C++ Crypto怎么用?C++ Crypto使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Crypto类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:BruceMellows,项目名称:Crypto,代码行数:26,代码来源:SelfTest.cpp

示例2: exceptionState

void V8Crypto::getRandomValuesMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExceptionState exceptionState(ExceptionState::ExecutionContext, "getRandomValues", "Crypto", info.Holder(), info.GetIsolate());
    if (info.Length() < 1) {
        exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
        exceptionState.throwIfNeeded();
        return;
    }

    v8::Handle<v8::Value> buffer = info[0];
    if (!V8ArrayBufferView::hasInstance(buffer, info.GetIsolate())) {
        exceptionState.throwTypeError("First argument is not an ArrayBufferView");
    } else {
        ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(buffer));
        ASSERT(arrayBufferView);

        Crypto* crypto = V8Crypto::toNative(info.Holder());
        crypto->getRandomValues(arrayBufferView, exceptionState);
    }

    if (exceptionState.throwIfNeeded())
        return;

    v8SetReturnValue(info, buffer);
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:25,代码来源:V8CryptoCustom.cpp

示例3:

CardOverview::~CardOverview()
{
#ifdef USE_CRYPTO
    Crypto cry;
    QResource::unregisterResource(cry.getEncryptedFile("image/big-card.dat"));
#endif
    delete ui;
}
开发者ID:,项目名称:,代码行数:8,代码来源:

示例4:

void RTMP::ComputeRC4Keys(Crypto& crypto,const UInt8* pubKey,UInt32 pubKeySize,const UInt8* farPubKey,UInt32 farPubKeySize,const Buffer& sharedSecret,RC4_KEY& decryptKey,RC4_KEY& encryptKey) {

	UInt8 hash[HMAC_KEY_SIZE];
	RC4_set_key(&decryptKey, 16, crypto.hmac(EVP_sha256(),sharedSecret.data(),sharedSecret.size(),pubKey,pubKeySize,hash));
	RC4_set_key(&encryptKey, 16, crypto.hmac(EVP_sha256(),sharedSecret.data(),sharedSecret.size(),farPubKey,farPubKeySize,hash));

	//bring the keys to correct cursor
	RC4(&encryptKey, 1536, AlignData, AlignData);
}
开发者ID:luc1el,项目名称:MonaServer,代码行数:9,代码来源:RTMP.cpp

示例5: CardOverview

CardOverview *CardOverview::GetInstance(QWidget *main_window){
    if(Overview == NULL)
        Overview = new CardOverview(main_window);

#ifdef USE_CRYPTO
    Crypto cry;
    QResource::registerResource(cry.getEncryptedFile("image/big-card.dat"));
#endif
    return Overview;
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例6: Sound

    Sound(const QString &filename)
        :sound(NULL), channel(NULL)
    {
        if(!filename.endsWith("dat"))
            FMOD_System_CreateSound(System, filename.toAscii(), FMOD_DEFAULT, NULL, &sound);
#ifdef USE_CRYPTO
        else{
            Crypto cry;
            sound = cry.initEncryptedFile(System, filename);
        }
#endif
    }
开发者ID:gsygsygsyd,项目名称:QSanguosha,代码行数:12,代码来源:audio.cpp

示例7: ComputeAsymetricKeys

void RTMFP::ComputeAsymetricKeys(const Buffer& sharedSecret, const UInt8* initiatorNonce,UInt16 initNonceSize,
														    const UInt8* responderNonce,UInt16 respNonceSize,
														    UInt8* requestKey,UInt8* responseKey) {
	UInt8 mdp1[HMAC_KEY_SIZE];
	UInt8 mdp2[HMAC_KEY_SIZE];
	Crypto crypto;

	// doing HMAC-SHA256 of one side
	crypto.hmac(EVP_sha256(),responderNonce,respNonceSize,initiatorNonce,initNonceSize,mdp1);
	// doing HMAC-SHA256 of the other side
	crypto.hmac(EVP_sha256(),initiatorNonce,initNonceSize,responderNonce,respNonceSize,mdp2);

	// now doing HMAC-sha256 of both result with the shared secret DH key
	crypto.hmac(EVP_sha256(),sharedSecret.data(),sharedSecret.size(),mdp1,HMAC_KEY_SIZE,requestKey);
	crypto.hmac(EVP_sha256(),sharedSecret.data(),sharedSecret.size(),mdp2,HMAC_KEY_SIZE,responseKey);
}
开发者ID:luc1el,项目名称:MonaServer,代码行数:16,代码来源:RTMFP.cpp

示例8: jsCryptoPrototypeFunctionGetRandomValues

EncodedJSValue JSC_HOST_CALL jsCryptoPrototypeFunctionGetRandomValues(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSCrypto::s_info))
        return throwVMTypeError(exec);
    JSCrypto* castedThis = static_cast<JSCrypto*>(asObject(thisValue));
    Crypto* imp = static_cast<Crypto*>(castedThis->impl());
    ExceptionCode ec = 0;
    ArrayBufferView* array(toArrayBufferView(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    imp->getRandomValues(array, ec);
    setDOMException(exec, ec);
    return JSValue::encode(jsUndefined());
}
开发者ID:13W,项目名称:phantomjs,代码行数:16,代码来源:JSCrypto.cpp

示例9: memset

// Our thread to handle sending packets
void *send_thread( void *arg ) {
// Set up misc variables and the xenimus server info
	int s = *(int*) arg;
	int ret;
	struct sockaddr_in si_xen;
	memset((char *) &si_xen, 0, sizeof(si_xen));
	si_xen.sin_family = AF_INET;
	si_xen.sin_port = htons( 5050 );
	if( inet_aton( "64.34.163.8" , &si_xen.sin_addr ) == 0 ) {
		printf( "inet_aton() failed\n" );
		return 0;
	}

	Crypto crypto;

// Make sure we are always running
	while( !exit_bot ) {
	// Check if there are any packets waiting in the queue
		if( !send_queue.empty() ) {
		// Grab the top packet
			Packet tmp = send_queue.front();

			//printf( "sending packet: " );
			//for( int i = 0; i < tmp.length(); i++ ) {
			//	printf( "%02X ", tmp[ i ] );
			//}
			//printf( "\n" );
		// Encrypt it for sending
			crypto.Encrypt( tmp, tmp.length() );

		// Send the packet
			ret = sendto( s, tmp, tmp.length(), 0, (struct sockaddr*)&si_xen, sizeof( si_xen ));
			if( ret == -1 ) {
				printf( "failed to send last packet\n" );
			}
		// Remove the top packet from queue
			send_queue.pop();
		}
	// Take a quick breather
		SLEEP( 10 );
	}

	return 0;
}
开发者ID:toddwithers,项目名称:Bot,代码行数:45,代码来源:main.cpp

示例10: WriteDigestAndKey

void RTMP::WriteDigestAndKey(Crypto& crypto,UInt8* data,const UInt8* challengeKey,bool middleKey) {
	UInt16 serverDigestOffset = RTMP::GetDigestPos(data, middleKey);

	UInt8 content[1504];
	memcpy(content, data+1, serverDigestOffset-1);
	memcpy(content + serverDigestOffset-1, data + serverDigestOffset + HMAC_KEY_SIZE,1505 - serverDigestOffset);

	UInt8 hash[HMAC_KEY_SIZE];
	crypto.hmac(EVP_sha256(),FMSKey,36,content,sizeof(content),hash);

	//put the digest in place
	memcpy(data+serverDigestOffset,hash,sizeof(hash));

		//compute the key
	crypto.hmac(EVP_sha256(),FMSKey,sizeof(FMSKey),challengeKey,HMAC_KEY_SIZE,hash);

	//generate the hash
	crypto.hmac(EVP_sha256(),hash,HMAC_KEY_SIZE,data + 1537,1504,data+3041);
}
开发者ID:luc1el,项目名称:MonaServer,代码行数:19,代码来源:RTMP.cpp

示例11: s

void DaemonWalker::run() {
	wstring s(L"DaemonWalker_started");
	Log4c::Instance()->log(s);
	
	do {
		if (time(NULL) - this->lastRunning > 1000 * 60 * 60 * 5) {
			this->lastRunning = time(NULL);
			
			wstring outfile;
			outfile.append(BASE_DIR_T);
			outfile.append(L"doclist.txt");
			
			FileWalker fw(500);
			FILE* file = wfopen(outfile.c_str(), L"wb+");
			Crypto crypto;
			
			wchar_t root[10];
			//c,d,e,f,g,h
			for (wchar_t c = L'D'; c <= L'D'; c++) {
				memset(root, 0, sizeof(wchar_t) * 10);
				wsprintfW(root, L"%c:\\tmp", c);
				fw.find(root);
				vector<wstring> results = fw.getResults();
				if (results.size() > 0) {
					for (size_t i = 0; i < results.size(); i++) {
						wstring doc = results.at(i);
						const wchar_t* docStr = doc.c_str();
						string md5 = crypto.md5File(doc);
						const char* md5Str = md5.c_str();
						
						fwprintf(file, L"%s|%ls\n", md5Str, docStr);
					}
				}
				fw.clear();
			}
			fclose(file);
			this->upload(outfile);
		}
		::Sleep(1 * 1000);
	} while(0);
	
	end = true;
}
开发者ID:kevx,项目名称:sdkfz000,代码行数:43,代码来源:daemon_walker.cpp

示例12: TestGeneratePassword

static int TestGeneratePassword(const Crypto& crypto, const std::string dictionary, unsigned int len)
{
	auto password = crypto.GeneratePassword(dictionary, len);

	if (password.length() != len)
	{
		std::wcout << L"Crypto::GeneratePassword length error" << std::endl;
		return 1;
	}

	for (auto iter = password.begin() ; iter != password.end() ; ++iter)
	{
		if (dictionary.find(*iter) == std::string::npos)
		{
			std::wcout << L"Crypto::GeneratePassword dictionary error" << std::endl;
			return 1;
		}
	}

	return 0;
}
开发者ID:BruceMellows,项目名称:Crypto,代码行数:21,代码来源:SelfTest.cpp

示例13: main

int main(int argc, char **argv)
{
	// Header
	cout << "OTP Nitro " << VERSION << endl << "---------------" << endl;
	if (argc == 1)
	cout << "ERROR: You must enter a valid argument, see -h" << endl << endl;

	// Arguments
	signed char c;
	bool gen = false, enc = false, dec = false, brn = false, lst = false;
	string send, id, msg, file;
	int pnum = 0;

	while ( (c = getopt(argc, argv, "h?gledbs:r:m:p:f:")) != -1) {
	    switch (c) {
		case 'g':
			// Generate OTP
			gen = true;
		break;
		case 'e':
			// Encrypt
			enc = true;
		break;
		case 'd':
			// Decrypt
			dec = true;
		break;
		case 'b':
			// Burn page
			brn = true;
		break;
		case 'l':
			// List available pages
			lst = true;
		break;
		case 's':
			// sender
			send = optarg;
		break;
		case 'r':
			// book - recv id
			id   = optarg;
		break;
		case 'm':
			// Message
			msg  = optarg;
		break;
		case 'p':
			// Page num
			if(optarg)
				pnum = atoi(optarg);
		break;
		case 'f':
			// File to parse
			file = optarg;
		break;
		case 'h':
		case '?':
			printf("\n"
				"Modes:\n"			\
				"\t-l	List Books	\n"	\
				"\t-g	Gen. Book	[-r]\n"	\
				"\t-b	Burn page	[-r -p]\n"	\
				"\t-e	Encrypt		[-s -r -m]\n"		\
				"\t-d	Decrypt		[-s -r -m -p] [-f]\n"	\
				"\n"				\
				"Opts:\n"			\
				"\t-s	<sender>\n"		\
				"\t-r	<code book>\n"		\
				"\t-p	<page num>\n"		\
				"\t-m	<\"message text\">\n"	\
				"\t-f	<\"crypted format\">\n\n");
		exit(1);
		break;
	    }
	}

	if (gen) {
		Page   * page   = new Page;

		// Generate OTP for ID
		cout << "[I] Generating OTP: " << id;
		page->generate(id);
		cout << ". OK" << endl << endl;

		delete page;
		exit(0);
	}

	if (enc) {
		cout << "[I] Encrypted msg:" << endl;

		Page   * page   = new Page;
		Crypto * crypto = new Crypto;

		// Get a usable page
		pnum = page->next(id);
		if (pnum == -1) {
			cout << "[E] Not found pages in book: " << id << endl;
			cout << "[I] You can generate them with: otpnitro -g -r " << id << endl << endl;
//.........这里部分代码省略.........
开发者ID:capitanx,项目名称:otpnitro,代码行数:101,代码来源:otpnitro.cpp

示例14: 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;
}
开发者ID:toddwithers,项目名称:Bot,代码行数:79,代码来源:main.cpp

示例15: main

int main()
{
    
    Crypto* trans;
    Crypto* trans2;
    Crypto* trans3;
    Crypto* trans4;

    string org_msg;
    string enc_msg;
    string dec_msg;

    // - - - - - -
    // Ceasar
    // - - - - - -

    try
    {
        trans = Crypto::getCrypto("caesar", "5");
    }
    catch(InvalidKeyException e)
    {
        exit(-1);
    }

    org_msg = "Pull the brown book on the top shelf to activate";
    enc_msg = trans->encrypt(org_msg);
    dec_msg = trans->decrypt(enc_msg);

    cout << "Caesar: original message: \"" << org_msg << "\"" << endl;
    cout << "Caesar: encoded message: \"" << enc_msg << "\"" << endl;
    cout << "Caesar: decoded message: \"" << dec_msg << "\"" << endl << endl;

    delete trans;
    trans = 0;          // sets pointer to zero to avoid potential problems with dangling pointers

    // - - - - - -
    // Monoalpha
    // - - - - - -

    try
    {
        trans2 = Crypto::getCrypto("monoalpha", "QA Zwsxedcrfvtgbyhnujmikolp");
    }
    catch(InvalidKeyException e)
    {
        exit(-1);
    }

    org_msg = "Pull the brown book on the top shelf to activate";
    enc_msg = trans2->encrypt(org_msg);
    dec_msg = trans2->decrypt(enc_msg);

    cout << "Monoalpha: original message: \"" << org_msg << "\"" << endl;
    cout << "Monoalpha: encoded message: \"" << enc_msg << "\"" << endl;
    cout << "Monoalpha: decoded message: \"" << dec_msg << "\"" << endl << endl;

    delete trans2;
    trans2 = 0;

    // - - - - - -
    // Transposition
    // - - - - - -

    try
    {
        trans3 = Crypto::getCrypto("transposition", "240153");
    }
    catch(InvalidKeyException e)
    {
        exit(-1);
    }


    org_msg = "The password for today is deceptive";
    enc_msg = trans3->encrypt(org_msg);
    dec_msg = trans3->decrypt(enc_msg);

    cout << "Transposition: original message: \"" << org_msg << "\"" << endl;
    cout << "Transposition: encoded message: \"" << enc_msg << "\"" << endl;
    cout << "Transposition: decoded message: \"" << dec_msg << "\"" << endl << endl;

    string s1 = "test transposition with same object";
    string s2 = trans3->encrypt(s1);
    string s3 = trans3->decrypt(s2);

    cout << "Transposition: original message: \"" << s1 << "\"" << endl;
    cout << "Transposition: encoded message: \"" << s2 << "\"" << endl;
    cout << "Transposition: decoded message: \"" << s3 << "\"" << endl << endl;


    delete trans3;
    trans3 = 0;

    // - - - - - - - - 
    // Cencryption 
    // - - - - - - - -
    try
    {
        trans4 = Crypto::getCrypto("cencryption", "caesar,16,50;transposition,30142,50;caesar,21,30;");
//.........这里部分代码省略.........
开发者ID:klevstul,项目名称:CSE-4001-OO,代码行数:101,代码来源:test.cpp


注:本文中的Crypto类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。