Reputation: 3
I have been trying to add the Botan library to my C++ project but I haven't figured it out yet. I am on Ubuntu 22.04 using CLion with CMake.
I downloaded the latest (3.3.0) release from GitHub and followed the documentation on building the library. I ran these commands on my system which installed the library successfully:
$ ./configure.py
$ make
$ make check
$ make install
When I created a new project in CLion named example
, I added the following to my CMakeLists.txt:
cmake_minimum_required(VERSION 3.27)
project(example)
set(CMAKE_CXX_STANDARD 17)
add_executable(example main.cpp)
find_package(Botan 3.3.0)
find_package(Botan 3.3.0 COMPONENTS rsa ecdsa tls13)
find_package(Botan 3.3.0 OPTIONAL_COMPONENTS tls13_pqc)
include_directories("/usr/include")
target_link_libraries(example "Downloads/Botan-3.3.0/libbotan-3.so")
I created a file called main.cpp
in which I added the RSA code example from the documentation:
#include <botan/auto_rng.h>
#include <botan/hex.h>
#include <botan/pk_keys.h>
#include <botan/pkcs8.h>
#include <botan/pubkey.h>
#include <botan/rng.h>
#include <iostream>
int main(int argc, char* argv[]) {
if(argc != 2) {
return 1;
}
std::string plaintext(
"Your great-grandfather gave this watch to your granddad for good luck. "
"Unfortunately, Dane's luck wasn't as good as his old man's.");
std::vector<uint8_t> pt(plaintext.data(), plaintext.data() + plaintext.length());
Botan::AutoSeeded_RNG rng;
// load keypair
Botan::DataSource_Stream in(argv[1]);
auto kp = Botan::PKCS8::load_key(in);
// encrypt with pk
Botan::PK_Encryptor_EME enc(*kp, rng, "OAEP(SHA-256)");
std::vector<uint8_t> ct = enc.encrypt(pt, rng);
// decrypt with sk
Botan::PK_Decryptor_EME dec(*kp, rng, "OAEP(SHA-256)");
Botan::secure_vector<uint8_t> pt2 = dec.decrypt(ct);
std::cout << "\nenc: " << Botan::hex_encode(ct) << "\ndec: " << Botan::hex_encode(pt2);
return 0;
}
But when I try to build my project, I get the following error:
fatal error: botan/auto_rng.h: No such file or directory
1 | #include <botan/auto_rng.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
I have tried some solutions online (although I found that most people are using Botan with Visual Studio on Windows) which require changing my CMakeLists.txt
many times and checking for case sensitivity but nothing has worked.
Upvotes: 0
Views: 175