在另一台机器上运行编译后的代码时崩溃(mingw-w64 32和64位工具链)cryptopp



我有一个问题无法理解。

首先,我正在制作一个使用Crypto++for RSA的程序。我已经分离了32位和64位mingw-w64的工具链。所以我下载了cryptopp源代码,为32位和64位构建了两次,并复制了lib和include文件。我使用了默认品牌。。。

所以我用静态库编译了我的代码,当我在编译的机器上运行它时,32位和64位都可以正常工作。但当我把它复制到另一台XP 64位或Win7 32位的机器上时,它在运行时会崩溃。在Win7上我只使用32位,在XP上我使用32和64位。

我搜索了一段时间,发现它在这个代码上崩溃了:

StringSource ss1(message, true,
        new SignerFilter(rng, signer,
            new StringSink(signature)
       )
    );

但只运行这个不会崩溃。

new SignerFilter(rng, signer,
                new StringSink(signature)
           )

有人知道它可能是什么吗?

这是我的测试代码

AutoSeededRandomPool rng;
string privKey, privKey_Base64 = 
"MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMm4ybhUat8MwkHwWxwEFQ/7
0wsJIT+Y3sIUFhwF8BslsJrhkTYYbhMYM9gHi/T5Y0m75h4jXesZNgfv0SUie1/6aWe61eZG
bCMUgWh/6+onNtQOiJV88VgxBJG45OOinlG3l7NJpZZukiEXNqlv4dj2mWLgt6cIC8Gz2QQh
cb9zAgERAoGANWWezukrWSkGPqGBh2p+C8KozjcfY6h3M1+rf+N0Q2vb7MM9Bso7QUor101K
scmLOSo1YlSn62iOTWUgxhCoL4WbZK2UDxrMhdtEV+i4jtkopceJF6x5XBOBYdKPjEbJxd2m
FPMBxA8NaI4D+WdSGCrzCSmAAp/A1qHFJZErdXkCQQD7P7htvv3slqYQMJZB+BLVMnE7TNOY
YLCxbAVRTM70pvE/sn9DwXQEJQcOTavv6hr1AU0OC70KtYxQDo5eN7ppAkEAzYlPaAQEn0Kf
x/lNQI/0j2rUGlJMA6m9bsw3TCR0hhmRa3HIb912o1bkYi9PTvp/JnO6UlaKvkTRq1N2EJXX
ewJBAN2wsco/HEk5oZXQhJSPmCWG3GGABf7r5zMjE8A0tpuiXGVhQx2qsalN2Qye4wDdn1Cm
y4TdLlS+TqD9yOm4s4kCQQC1WwnUP8fX0V/OkK2TUdfJ1rsmSJ1spNRStDDKtsErB4BPvr/q
O+EmthTPGq9jzfe4hDr9W2tclxNa70oOolS3AkEA7qZDM0BHALxK/2Q6lU2zpjfh1gUxLAlg
OGyIGTafq1o0y2b5HGrmwVYQAGaUPlBLVRLRBxhL+kXnSzXhTR1xRA==
";
CryptoPP::StringSource tasdst(privKey_Base64, true, new CryptoPP::Base64Decoder(new CryptoPP::StringSink(privKey)));
string pubKey, pubKey_Base64 =
"MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQDJuMm4VGrfDMJB8FscBBUP+9MLCSE/mN7C
FBYcBfAbJbCa4ZE2GG4TGDPYB4v0+WNJu+YeI13rGTYH79ElIntf+mlnutXmRmwjFIFof+vq
JzbUDoiVfPFYMQSRuOTjop5Rt5ezSaWWbpIhFzapb+HY9pli4LenCAvBs9kEIXG/cwIBEQ==
";
CryptoPP::StringSource tasdst2(pubKey_Base64, true, new CryptoPP::Base64Decoder(new CryptoPP::StringSink(pubKey)));
RSA::PrivateKey privateKey;
char const *a = privKey.c_str();
size_t dataLen = privKey.size();
privateKey.Load(CryptoPP::StringStore((const byte*)a,(size_t)dataLen).Ref());
RSA::PublicKey publicKey;
char const *b = pubKey.c_str();
dataLen = pubKey.size();
publicKey.Load(CryptoPP::StringStore((const byte*)b,(size_t)dataLen).Ref());
string message = "RSA Signature", signature;
std::cout << message << std::endl;
RSASSA_PKCS1v15_SHA_Signer signer(privateKey);
StringSource ss1(message, true,
    new SignerFilter(rng, signer,
        new StringSink(signature)
    )
);
string encoded, decoded;
CryptoPP::StringSource(signature, true, new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded)));
CryptoPP::StringSource tasdst3(encoded, true, new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded)));
RSASSA_PKCS1v15_SHA_Verifier verifier(publicKey);
StringSource ss2(message+decoded, true,
    new SignatureVerificationFilter(
        verifier, NULL,
        SignatureVerificationFilter::THROW_EXCEPTION
    )
);

环顾四周。我发现构建libcryptopp有问题,只需几行代码就可以修复以前的症状。

以下是GNUmakefile中要更改的内容:https://sites.google.com/site/ievgensychov/cryptopp

是的,问题解决了。

相关内容

  • 没有找到相关文章

最新更新