I am using crypto++ AES to encrypt and decrypt.
I have the key stored as string type in database for some reason.
How do I assign this key to the AES SecByteBlock key or initialize the AES key with this value instead of some random generated blocks.
std::string key_fromDB = "12dfre314?//1afsfa";
AutoSeededRandomPool prng;
byte iv[ AES::BLOCKSIZE ];
prng.GenerateBlock( iv, sizeof(iv) );
SecByteBlock temp_key(AES::DEFAULT_KEYLENGTH);
prng.GenerateBlock( temp_key, temp_key.size() );
try
{
CBC_Mode< AES >::Decryption d;
d.SetKeyWithIV(temp_key , temp_key.size(), iv );
// The StreamTransformationFilter removes
// padding as required.
StringSource ss( cipher, true,
new StreamTransformationFilter( d,
new StringSink( recovered )
) // StreamTransformationFilter
); // StringSource
std::cout << "recovered text: " << recovered << std::endl;
}
catch ( const CryptoPP::Exception& e)
{
std::cerr << e.what() << std::endl;
}