本文整理汇总了C++中CryptoPP::FileSource方法的典型用法代码示例。如果您正苦于以下问题:C++ CryptoPP::FileSource方法的具体用法?C++ CryptoPP::FileSource怎么用?C++ CryptoPP::FileSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CryptoPP
的用法示例。
在下文中一共展示了CryptoPP::FileSource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadKey
void LoadKey(const string& filename, RSA::PrivateKey& PrivateKey)
{
// DER Encode Key - PKCS #8 key format
PrivateKey.Load(
FileSource(filename.c_str(), true, NULL, true /*binary*/).Ref()
);
}
示例2: decrypt_file
void decrypt_file(string efile) //keep hash
{
string efilename = efile;
efile.erase(efile.end()-4, efile.end());
string rfilename = efile;
//SecByteBlock key(AES::MAX_KEYLENGTH);
//byte iv[ AES::BLOCKSIZE ];
if(decMode == "OFB")
{
OFB_Mode< AES >::Decryption d2;
d2.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );
FileSource( efilename.c_str(), true,
new StreamTransformationFilter( d2,
new FileSink( rfilename.c_str() )));
}
else if(decMode == "CFB")
{
CFB_Mode< AES >::Decryption d2;
d2.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );
FileSource( efilename.c_str(), true,
new StreamTransformationFilter( d2,
new FileSink( rfilename.c_str() )));
}
else if(decMode == "GCM")
{
GCM< AES >::Decryption d2;
d2.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );
FileSource fs2( efilename.c_str(), true,
new AuthenticatedDecryptionFilter( d2,
new FileSink( rfilename.c_str() ),
AuthenticatedDecryptionFilter::THROW_EXCEPTION));
}
else
{
cerr << "Decryption Error" <<endl;
}
}
示例3: main
int main(int argc, char* argv[])
{
AutoSeededRandomPool prng;
byte fkey[SHA256::DIGESTSIZE];
string key_from_file, plain;
byte key[AES::MAX_KEYLENGTH]; // 32 bytes
string filename=argv[2];
string share_fkey;
FileSource(argv[1], true,
new HexDecoder(
new StringSink(key_from_file))
);
//removing directory paths if any
filename = filename.substr(filename.find_last_of("/")+1,filename.length());
byte iv[AES::BLOCKSIZE]; // 16 bytes
iv[0] = 0;
//prng.GenerateBlock(iv, sizeof(iv));
string temp = key_from_file+filename;
byte digest_input[temp.length()];
for (int i=0;i<=temp.length();i++)
digest_input[i]=temp[i];
SHA256().CalculateDigest(fkey, digest_input, sizeof(digest_input));
StringSource(fkey, sizeof(fkey),true,
new HexEncoder(
new StringSink(share_fkey))
);
cout<<"fkey to share : "<<share_fkey<<endl;
string new_filename = filename.substr(filename.find_last_of(".")+1,filename.length()) + '.' + filename.substr(0,filename.find_last_of("."));
byte efile[SHA256::DIGESTSIZE];
string encoded_efile;
byte filename_plain_input[new_filename.length()];
for (int i=0;i<=new_filename.length();i++)
filename_plain_input[i]=(byte)new_filename[i];
SHA256().CalculateDigest(efile, filename_plain_input, sizeof(filename_plain_input));
StringSource(efile, sizeof(efile), true,
new HexEncoder(
new StringSink(encoded_efile)
) // HexEncoder
); // StringSource
cout<<"the filename on cloud server : "<<encoded_efile<<endl<<endl;
return 0;
}
示例4: decrypt_file
void decrypt_file(string efile)
{
string efilename = efile;
efile.erase(efile.end()-4, efile.end());
string rfilename = efile;
//SecByteBlock key(AES::MAX_KEYLENGTH);
//byte iv[ AES::BLOCKSIZE ];
OFB_Mode< AES >::Decryption d2;
d2.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );
FileSource( efilename.c_str(), true,
new StreamTransformationFilter( d2,
new FileSink( rfilename.c_str() )
) // StreamTransformationFilter
); // StringSource
}