本文整理汇总了C++中CryptoPP::SHA256方法的典型用法代码示例。如果您正苦于以下问题:C++ CryptoPP::SHA256方法的具体用法?C++ CryptoPP::SHA256怎么用?C++ CryptoPP::SHA256使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CryptoPP
的用法示例。
在下文中一共展示了CryptoPP::SHA256方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}