问题描述
我正在尝试使用 C++ 密码学库 Botan 对密码进行哈希处理。我已尝试使用以下代码测试该库:
#include <iostream>
#include <string>
#include <botan/argon2.h>
#include <botan/system_rng.h>
int main() {
Botan::System_RNG rng;
std::string password = "cool_password";
std::string generated_hash = Botan::argon2_generate_pwhash(password.c_str(),password.length(),rng,1,4000,1); // crash occurs here
std::cout << generated_hash << "\n";
}
但是代码要么打印了垃圾数据,要么给了我一个运行时错误:
Unhandled exception at 0x00007FFEF11825E0 (ucrtbased.dll) in app.exe: 0xC0000005: Access violation reading location 0x0000000100000000.
我该怎么办?使用其他散列方法,例如 Botan::generate_bcrypt() 也会导致相同的错误。
解决方法
经过 4 小时痛苦的故障排除并一遍又一遍地使用不同的编译器重建库后,我发现如果 Visual Studio 中的“解决方案配置”未设置为“发布”而不是“调试”,则 Botan 无法正常工作.