Wednesday, February 05, 2014

Quick AES Encrypt String with Botan C++

AutoSeeded_RNG rng;
SymmetricKey key(rng, 16); // a random 128-bit key
InitializationVector iv(rng, 16); // a random 128-bit IV
Pipe pipe(get_cipher("AES-128/CBC", key, iv, ENCRYPTION), new Hex_Encoder);
pipe.process_msg("secrets");
std::string m1 = pipe.read_all_as_string(0);
Pipe pipe2(new Hex_Decoder, get_cipher("AES-128/CBC", key, iv, DECRYPTION));
pipe2.process_msg(m1.c_str());
std::string m2 = pipe2.read_all_as_string(0);

No comments: