I'm just getting started with Botan. I have included the botan_all.h in my code file and am linking to the libbotan-2.a library when building.
Here is the relevant part of main.cpp:
#include "botan_all.h"
int main(int argc, char *argv[])
{
const std::vector<uint8_t> key = Botan::hex_decode("2B7E151628AED2A6ABF7158809CF4F3C");
std::unique_ptr<Botan::Cipher_Mode> enc = Botan::Cipher_Mode::create("AES-128/CBC/PKCS7", Botan::ENCRYPTION);
enc->set_key(key);
}
The enc->set_key(key) causes a seg fault. What am I missing?
This is likely caused by your Botan version not being build with support for the specified algorithm. The method
CipherMode::createreturns anullptrif the specified algorithm is not found (reference). You would then have to check the result, e.g.:Alternatively, you could use
CipherMode::create_or_throw(reference):You can also check your Botan headers for support for these specific algorithms, by checking if
BOTAN_HAS_AESandBOTAN_HAS_MODE_CBCare defined. If these are not available, you would have to ensure that when you compile botan, you include AES and CBC support, e.g. with: