【发布时间】:2018-09-22 12:56:44
【问题描述】:
我正在使用 Botan C++ 库来签署和验证一些 license.ini 文件。我已经设置 Botan PK_Signer 使用 RSA 算法来加密使用 PKCS v1.5 创建的散列。这是我的代码:
uint8_t private_key[] = "private key I already have generated."
// Read file content that needs to be signed.
std::string licensePath = argv[1];
std::string fileContents = readFileContent(licensePath);
// Prepare Botan RSA signer. PKCS1 v1.5 is used.
Botan::AutoSeeded_RNG rng;
Botan::secure_vector<uint8_t> secure_key_vector(private_key, private_key + sizeof(private_key) / sizeof(private_key[0]));
/////// NEXT LINE THROWS EXCEPTION!
Botan::RSA_PrivateKey rsa_priv_key(Botan::AlgorithmIdentifier(), secure_key_vector);
//////////////////////////////////////
Botan::PK_Signer signer(rsa_priv_key, rng, "EMSA-PKCS1-v1_5");
// Create signature.
signer.update(cleanStr(fileContents));
std::vector<uint8_t> signature = signer.signature(rng);
std::string hexSignature = Botan::hex_encode(signature);
生成RSA_PrivateKey对象的标记线抛出异常:
在 0x00007FF85D2BC3C7 (vcruntime140.dll) 处引发异常 license_signer.exe: 0xC0000005: 访问冲突读取位置 0x0000021A8FA07000.
我以前从未使用过 Botan 库。如果有人知道为什么会发生这种情况或知道如何实施,请提供帮助。谢谢。
【问题讨论】:
-
确保库和您的应用程序是使用相同的 MSVC 运行时选项构建的。如果它们不匹配,则症状通常是崩溃。 Botan 构建默认为
/MD。