本文整理汇总了C++中AES::GenerateKey方法的典型用法代码示例。如果您正苦于以下问题:C++ AES::GenerateKey方法的具体用法?C++ AES::GenerateKey怎么用?C++ AES::GenerateKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AES
的用法示例。
在下文中一共展示了AES::GenerateKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RunAESDemo
int RunAESDemo()
{
AES aes;
vector<unsigned char> key;
aes.GenerateKey( 256, key );
printf( "key.size(): %d\n", (int)key.size() );
// unsigned char buffer[50000]; // 50KB
size_t read_bytes = 0;
vector<unsigned char> plaintext;
plaintext.resize(50000,0);
// string plaintext_file = "input_data/plaintext/plaintext_example.txt";
// string plaintext_file = "input_data/plaintext/0s.txt";
string plaintext_file = "input_data/plaintext/more0s.txt";
FILE *fp = fopen( plaintext_file.c_str(), "rb" );
if(fp)
{
// read_bytes = fread(buffer,sizeof(buffer),1,fp);
read_bytes = fread(&plaintext[0], sizeof(unsigned char), plaintext.size(), fp);
printf( "read_bytes: %d\n", (int)read_bytes );
fclose(fp);
}
vector<unsigned char> ciphertext;
aes.Encrypt( plaintext, ciphertext );
printf( "ciphertext.size(): %d\n", (int)ciphertext.size() );
if( 0 < ciphertext.size() )
{
fp = fopen( string(plaintext_file + ".encrypted").c_str(), "wb" );
if(fp)
{
size_t written_bytes = fwrite(&ciphertext[0], sizeof(unsigned char), ciphertext.size(), fp);
printf( "written_bytes: %d\n", (int)written_bytes );
fclose(fp);
}
}
return 0;
}