gpt4 book ai didi

c++ - 调试断言失败

转载 作者:太空宇宙 更新时间:2023-11-04 11:41:25 24 4
gpt4 key购买 nike

我是 Crypto++ 的新手,我需要对我的字符串和整数进行一些操作(调用哈希函数和 MAC 函数)

我看到了 Using Crypto++ to generate random hashes with SHA1并试图跟随它。

我创建了新项目,编译了 cryptolibs,链接了它们(我认为是正确的,因为没有链接器错误)。它构建良好,但从 main 返回时我有这个:

DEBUG ASSERTION FAILED! ...blablabla/dbgdel.cpp Line 52

Expression: _Block_Type_Is_Valid(pHead->nBlockUse) ...

我就像在评论中的那些帖子一样,所以我不明白为什么会这样。

代码(包含就像地址,因为我真的懒得在链接器上建立良好的链接):

#include <C:\Users\esselesse\Documents\Visual Studio 2010\Projects\InfoProtect_Biometrics_Auth_Algorithm\InfoProtect_Biometrics_Auth_Algorithm\LIB\sha.h>
#include <C:\Users\esselesse\Documents\Visual Studio 2010\Projects\InfoProtect_Biometrics_Auth_Algorithm\InfoProtect_Biometrics_Auth_Algorithm\LIB\filters.h>
#include <C:\Users\esselesse\Documents\Visual Studio 2010\Projects\InfoProtect_Biometrics_Auth_Algorithm\InfoProtect_Biometrics_Auth_Algorithm\LIB\hex.h>
#include <iostream>
#include <string>

using namespace CryptoPP;
using namespace std;

int main()
{
SHA1 sha1;
string source = "Hello"; //This will be randomly generated somehow
string hash = "";
StringSource(source, true, new HashFilter(sha1, new HexEncoder(new StringSink(hash))));
}

最佳答案

DEBUG ASSERTION FAILED! ...blablabla/dbgdel.cpp Line 52

Expression: _Block_Type_Is_Valid(pHead->nBlockUse) ...

那是来自 Visual Studio,而不是 Crypto++。你有内存问题。


$ cat t.cpp
// g++ -I/usr/local/include t.cpp -o t.exe -lcryptopp -lpthread

#include <cryptopp/sha.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>

#include <iostream>
#include <string>

using namespace CryptoPP;
using namespace std;

int main()
{
SHA1 sha1;
string source = "Hello"; //This will be randomly generated somehow
string hash = "";
StringSource(source, true, new HashFilter(sha1, new HexEncoder(new StringSink(hash))));

cout << hash << endl;

return 0;
}

对我来说运行良好:

$ ./t.exe
F7FF9E8B7BB2E09B70935A5D785E0CC5D9D0ABF0
$

我怀疑缺少一些信息 - 比如您正在使用您提到的字符串和整数(但没有向我们展示)。

您需要向我们展示您尝试运行的代码。


I made new project, compiled cryptolibs, linked them (I think, correctly, because there is no linker errors).

您还可以验证您的项目是否按 Visual Studio 的预期设置。为此,请参阅 Compiling and Integrating Crypto++ into the Microsoft Visual C++ Environment .

关于c++ - 调试断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21261764/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com