本文整理汇总了C++中rsa::PrivateKey::BERDecode方法的典型用法代码示例。如果您正苦于以下问题:C++ PrivateKey::BERDecode方法的具体用法?C++ PrivateKey::BERDecode怎么用?C++ PrivateKey::BERDecode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rsa::PrivateKey
的用法示例。
在下文中一共展示了PrivateKey::BERDecode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: signature
std::string BCipher::signature(std::string content){
std::string keyfile,signature,cipher1;
std::cout<<"Begin to implement digital signature"<<std::endl;
RSA::PrivateKey rsaPrivate;
std::cout<<"Signature by sender's private key"<<std::endl;
{
FileSource input("sender_private.dat", true);
rsaPrivate.BERDecode(input);
}
RSASSA_PKCS1v15_SHA_Signer signer(rsaPrivate);
AutoSeededRandomPool rng;
StringSource ss3(content, true,
new SignerFilter(rng, signer,
new StringSink(cipher1)
) // SignerFilter
); // StringSource
std::cout<<"Sending files to cloud server"<<std::endl;
return cipher1;
}
示例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;
//.........这里部分代码省略.........