我正在使用Botan C++库对一些license.ini文件进行签名和验证。我已经将PK_Signer设置为使用RSA算法来加密用PKCSv1.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对象的标记行引发异常:
在license_signer.exe: 0xC0000005:访问冲突读取位置0x0000021A8FA07000中0x00007FF85D2BC3C7 (vcruntime140.dll)引发的异常。
我以前从未使用过博坦图书馆。如果有人知道为什么会发生这种情况,或者知道如何实施,请协助。谢谢。
发布于 2018-04-12 12:07:23
您试图使用的构造函数中的private_key数据必须经过DER编码。确定是的。但是,通常情况下,最好使用适当的loadKey方法。
发布于 2020-03-07 07:25:56
使用Botan 2.12.1
#include <string>
#include <botan/auto_rng.h>
#include <botan/auto_rng.h>
#include <botan/base64.h>
#include <botan/pkcs8.h>
#include <botan/rsa.h>
#include <botan/x509_key.h>
#include <botan/data_src.h>
#include <botan/pubkey.h>
//Assuming the private and public keys are in Base64 encoded BER.
Botan::AutoSeeded_RNG rng;
Botan::RSA_PrivateKey keyPair(rng, static_cast<size_t>(4096));
std::string privateKey = Botan::base64_encode(Botan::PKCS8::BER_encode(keyPair));
std::string publicKey = Botan::base64_encode(Botan::X509::BER_encode(keyPair));
//Loading the public key
Botan::SecureVector<uint8_t> keyBytes(Botan::base64_decode(publicKey));
std::unique_ptr<Botan::Public_Key> pbk(Botan::X509::load_key(std::vector(keyBytes.begin(), keyBytes.end())));
//Loading the private key
Botan::SecureVector<uint8_t> keyBytes(Botan::base64_decode(privateKey));
Botan::DataSource_Memory source(keyBytes);
std::unique_ptr<Botan::Private_Key> pvk(Botan::PKCS8::load_key(source));https://stackoverflow.com/questions/49795411
复制相似问题