调试断言失败

时间:2014-01-21 15:05:07

标签: c++ memory crypto++

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

我看到了这个 Using Crypto++ to generate random hashes with SHA1并试图遵循它。

我创建了新项目,编译了cryptolibs,将它们链接起来(我认为正确,因为没有链接器错误)。它建立良好,但从主要回来我有这个:

  

DEBUG ASSERTION FAILED! ... blablabla / dbgdel.cpp第52行

     

表达式:_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))));
}

1 个答案:

答案 0 :(得分:1)

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
$ 

我怀疑有一些信息丢失了 - 比如你用你的字符串和你提到的注意事项(但没有告诉我们)。

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


  

我创建了新项目,编译了cryptolibs,将它们链接起来(我认为正确,因为没有链接器错误)。

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

相关问题