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


C++ PublicKey::BERDecode方法代码示例

本文整理汇总了C++中rsa::PublicKey::BERDecode方法的典型用法代码示例。如果您正苦于以下问题:C++ PublicKey::BERDecode方法的具体用法?C++ PublicKey::BERDecode怎么用?C++ PublicKey::BERDecode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rsa::PublicKey的用法示例。


在下文中一共展示了PublicKey::BERDecode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: verify_signature

void BCipher::verify_signature(std::string content,std::string signature){
        std::cout<<"Receiver verifies signature using sender's publickey"<<std::endl;
        RSA::PublicKey rsaPublickey;
        {
         FileSource input("sender_public.dat", true);
         rsaPublickey.BERDecode(input);
        }
 
	RSASSA_PKCS1v15_SHA_Verifier verifier(rsaPublickey);
        StringSource ss4(content + signature, true,
           new SignatureVerificationFilter(
               verifier, NULL,
               SignatureVerificationFilter::THROW_EXCEPTION
          ) // SignatureVerificationFilter
        ); // StringSource

        std::cout << "Verified signature on message" << std::endl;

}
开发者ID:XuefengHuang,项目名称:Cloud_Encrypted,代码行数:19,代码来源:bcipher.cpp

示例2: decrypt

void BCipher::decrypt(std::string fkfile,std::string filename,std::string encryptedfile,std::string decryptedfile,std::string content,std::string signature){
	AutoSeededRandomPool rng;
        RSA::PrivateKey privateKey;
        {
         FileSource input("receiver_private.dat", true);
         privateKey.BERDecode(input);
        }

        RSA::PublicKey publicKey;
        {
         FileSource input("receiver_public.dat", true);
         publicKey.BERDecode(input);
        }

	//InvertibleRSAFunction params;
	//params.GenerateRandomWithKeySize(rng, 3072);

	//RSA::PrivateKey privateKey(params);
	//RSA::PublicKey publicKey(params);
	std::cout<<"Sending public key to sender..."<<std::endl;
	std::string plain, cipher, recovered, cipher1,hmaccontents;
	std::stringstream ss;
        //read key file
	std::ifstream infk(fkfile.c_str());
	ss << infk.rdbuf();
	std::string fk = ss.str();
	ss.str("");
	infk.close();
	plain=fk;
        
        //read HMAC file
	std::ifstream inmd5(("hmac_"+encryptedfile).c_str());
	ss << inmd5.rdbuf();
	//std::string hmaccontents = ss.str();
        std::string hmac = ss.str();
	ss.str("");
	inmd5.close();

	// Encryption
	std::cout<<"User encrypting key and HMAC of uploaded file with public key..."<<std::endl;
	RSAES_OAEP_SHA_Encryptor e(publicKey);

	StringSource ss1(plain, true,
	    new PK_EncryptorFilter(rng, e,
	        new StringSink(cipher)
	   ) // PK_EncryptorFilter
	); // StringSource

	StringSource ss3(hmac, true,
	    new PK_EncryptorFilter(rng, e,
	        new StringSink(cipher1)
	   ) // PK_EncryptorFilter
	); // StringSource
        
	std::cout<<"Encryption Complete.\nSender now sharing the encrypted key and HMAC of uploaded file over unsecure channel..."<<std::endl;

        std::ofstream encrtptedkey("ekey.txt");
	encrtptedkey << cipher;
        encrtptedkey.close();

        std::ofstream encrtptedhmac("ehmac_efile.txt");
	encrtptedhmac << cipher1;
        encrtptedhmac.close();

	std::cout<<"Peer receives the encrypted files."<<std::endl;
	std::cout<<"Decrypting the files using his private key..."<<std::endl;

	// Decryption
	RSAES_OAEP_SHA_Decryptor d(privateKey);

	StringSource ss2(cipher, true,
	    new PK_DecryptorFilter(rng, d,
	        new StringSink(recovered)
	   ) // PK_DecryptorFilter
	); // StringSource

	StringSource ss4(cipher1, true,
	    new PK_DecryptorFilter(rng, d,
	        new StringSink(hmaccontents)
	   ) // PK_DecryptorFilter
	); // StringSource

	fk=recovered;

        std::cout<<"====================================================================="<<std::endl;
        //check if file is what I want.
        authorize(filename);
        std::cout<<"====================================================================="<<std::endl;
        // verify digital signature.     
        verify_signature(content,signature);
        std::cout<<"====================================================================="<<std::endl;

	Hexa b;
	std::string hmackey = fk.substr(AES::MAX_KEYLENGTH*2 + AES::BLOCKSIZE*2,HMAC_KEYLENGTH*2);
	std::string skey = fk.substr(0,AES::MAX_KEYLENGTH*2);
	std::string siv = fk.substr(AES::MAX_KEYLENGTH*2,AES::BLOCKSIZE*2);
        //std::cout<<hmackey<<std::endl;
        //std::cout<<skey<<std::endl;
        //std::cout<<siv<<std::endl;

//.........这里部分代码省略.........
开发者ID:XuefengHuang,项目名称:Cloud_Encrypted,代码行数:101,代码来源:bcipher.cpp


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