I'm new in C++ and I really stuck using Botan to connect to a hardware cryptography token. I don't know If I missed any setups for libs or dlls.
I built Botan library based on Building Botan library in Windows 10. botan.lib
and botan.dll
is created in lib folder after building.
Then I create a consoleApplication in Visual Studio 2019 with this simple code:
#include <iostream>
#include <botan/botan.h>
#include <botan/p11.h>
#include <botan/p11_slot.h>
#include <botan/p11_session.h>
#include <botan/p11_module.h>
#include <botan/p11_object.h>
#include <botan/p11_randomgenerator.h>
#include <botan/p11_x509.h>
#include <botan/x509_dn.h>
using namespace Botan;
using namespace PKCS11;
int main()
{
Botan::PKCS11::Module module("C:\\Windows\\System32\\ShuttleCsp11_3003.dll");
// Sometimes useful if a newly connected token is not detected by the PKCS#11 module
module.reload();
Botan::PKCS11::Info info = module.get_info();
// print library version
std::cout << std::to_string(info.libraryVersion.major) << "."
<< std::to_string(info.libraryVersion.minor) << std::endl;
}
This is the settings I prepared to run:
Configuration Properties→VC++ Directories:
- Include Directories → add C:\Botan\include\botan-2;
- Executable Directories → add C:\Botan\bin;
- Library Directory → add C:\Botan\lib;
- Source Directory → add C:\Botan\src;
- Additional Include Library → add C:\Botan\include\botan-2
Linker
- Additional Library Directory → add C:\Botan\lib;
- Input → Additional Dependencies → add C:\Botan\lib\botan.lib
Also I installed token driver which dll is in System32 folder;
As I build the Botan Library with x86 so I debug the project with this config:
The error which I need your help to solve is:
Unhandled exception at 0x74CD2CF2 in ConsoleApplication1.exe: Microsoft C++ exception:
std::bad_alloc at memory location 0x004FF1AC.
This error occurred in this line of Code:
Botan::PKCS11::Module module("C:\\Windows\\System32\\ShuttleCsp11_3003.dll");
And this is the call stack
Note that I copied botan.dll and ShuttleCsp11_3003.dll in debug folder.
Somebody please help, thanks