2014-01-21 156 views
1

我在加密+是新的,我需要做一些操作与我的字符串和整数(称之为散列函数和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
DEBUG ASSERTION FAILED! ...blablabla/dbgdel.cpp Line 52 

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

这是从Visual Studio来了,不加密+。你有一个记忆问题。


$ 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

+0

哇,谢谢你!有用) –