Crypto ++,_ BLOCK_TYPE_IS_VALID错误 [英] Crypto++, _BLOCK_TYPE_IS_VALID error

查看:99
本文介绍了Crypto ++,_ BLOCK_TYPE_IS_VALID错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从其他网站复制了这段代码并且无法编译它;我是密码学的新手,虽然我尽力让这个工作,但我一直得到表达式:_BLOCK_TYPE_IS_VALID(pHead-> nBlockUse)我知道这个错误与堆有关但我没有执行任何操作删除这几行代码。



  #include     dll.h 
< span class =code-keyword> #include modes.h
#include aes.h
#include < span class =code-preprocessor> filters.h
#include iostream
#include cryptlib.h


int main( int argc , char * argv []){


//
// 密钥和IV设置
//

字节键[CryptoPP :: AES :: DEFAULT_KEYLENGTH],iv [CryptoPP :: AES :: BLOCKSIZE];
memset(密钥,0x00,CryptoPP :: AES :: DEFAULT_KEYLENGTH);
memset(iv,0x00,CryptoPP :: AES :: BLOCKSIZE);


//
// 字符串和接收器设置
//
std :: string plaintext = 现在是所有好人来到助手的时候......;
string ciphertext;
std :: string decryptedtext;

//
// 转储纯文本
//
std :: cout<< 纯文本(<< plaintext.size()<< bytes)<<的std :: ENDL;
std :: cout<<纯文本;
std :: cout<< std :: endl<<的std :: ENDL;

//
// 创建密文
//

CryptoPP :: AES ::加密aesEncryption(密钥,CryptoPP :: AES :: DEFAULT_KEYLENGTH);
CryptoPP :: CBC_Mode_ExternalCipher ::加密cbcEncryption(aesEncryption,iv);

CryptoPP :: StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP :: StringSink(ciphertext));
stfEncryptor.Put(reinterpret_cast< const unsigned char *>(plaintext.c_str() ),plaintext.length()+ 1 );
stfEncryptor.MessageEnd();





//
// 转储密文
//
std :: cout<< 密文(<< ciphertext.size()<< bytes)<<的std :: ENDL;

for unsigned int i = 0 ; i< ciphertext.size(); i ++){

std :: cout<< 0x<< std :: hex<< (0xFF& static_cast< byte>(ciphertext [i]))<< ;
}

std :: cout<< std :: endl<<的std :: ENDL;

//
// 解密
//

CryptoPP :: AES ::解密aesDecryption(密钥,CryptoPP :: AES :: DEFAULT_KEYLENGTH);
CryptoPP :: CBC_Mode_ExternalCipher ::解密cbcDecryption(aesDecryption,iv);

CryptoPP :: StreamTransformationFilter * stfDecryptor = new CryptoPP :: StreamTransformationFilter(cbcDecryption, new CryptoPP :: StringSink(decryptedtext));
stfDecryptor-> Put(reinterpret_cast< const unsigned char *>(ciphertext.c_str ()),ciphertext.size());
stfDecryptor-> MessageEnd();

//
// 转储解密文本
//

std :: cout<< 解密文本:<<的std :: ENDL;
std :: cout<< decryptedtext;
std :: cout<< std :: endl<<的std :: ENDL;



return 0 ;
}







值得一提的是,如果我评论这两行,我不会t得到堆错误

 stfEncryptor.Put(reinterpret_cast< const  unsigned   char  *>(plaintext.c_str()),plaintext.length()+  1 ); 
stfEncryptor.MessageEnd();





我尝试调试它,错误在最后一次返回0之前弹出,我认为在调用类Destructor时,de-allocation导致了这个问题?





任何帮助都将不胜感激。

解决方案

我自己找到了解决方案;在编译CryptoPP的源代码时,在 解决方案属性 (cryptdll)中,在 C / C ++ 菜单下有一个名为<的子菜单b>代码生成,字段运行时库应该是多线程调试DLL(/ MDd)。谢谢你的时间。告别。

Hi, I have copied this piece of code from another site and have trouble compiling it; I'm new to cryptography and whilst I tried my best to get this to work, i keep getting "Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" I know this error has to do with the heap but I didn't perform any Delete in these few lines of code.

#include "dll.h" 
#include "modes.h"
#include "aes.h"
#include "filters.h"
#include "iostream"
#include "cryptlib.h"


int main(int argc, char* argv[]) {


    //
    // Key and IV setup
    //
	
    byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ];
    memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH );
    memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE );


    //
    // String and Sink setup
    //
    std::string plaintext = "Now is the time for all good men to come to the aide...";
    string ciphertext;
    std::string decryptedtext;

    //
    // Dump Plain Text
    //
    std::cout << "Plain Text (" << plaintext.size() << " bytes)" <<    std::endl;
    std::cout << plaintext;
    std::cout << std::endl << std::endl;

    //
    // Create Cipher Text
    //
	
	CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
    CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, iv );

    CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink(     ciphertext ) ); 
    stfEncryptor.Put( reinterpret_cast<const unsigned char*>( plaintext.c_str() ), plaintext.length() + 1   );
    stfEncryptor.MessageEnd();


	

	
    //
    // Dump Cipher Text
    //
    std::cout << "Cipher Text (" << ciphertext.size() << " bytes)" << std::endl;

    for( unsigned int i = 0; i < ciphertext.size(); i++ ) {

        std::cout << "0x" << std::hex << (0xFF & static_cast<byte>(ciphertext[i])) << " ";
    }

    std::cout << std::endl << std::endl;

    //
    // Decrypt
    //
    
	CryptoPP::AES::Decryption aesDecryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
    CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );

    CryptoPP::StreamTransformationFilter * stfDecryptor=new  CryptoPP::StreamTransformationFilter(cbcDecryption, new CryptoPP::StringSink( decryptedtext  ) );
    stfDecryptor->Put( reinterpret_cast<const unsigned char*>( ciphertext.c_str() ), ciphertext.size() );
    stfDecryptor->MessageEnd();

    //
    // Dump Decrypted Text
    //
	
    std::cout << "Decrypted Text: " << std::endl;
    std::cout << decryptedtext;
    std::cout << std::endl << std::endl;

	

    return 0;
}




While it is worth mentioning if I comment these two lines I don't get the heap error anymore

stfEncryptor.Put( reinterpret_cast<const unsigned char*>( plaintext.c_str() ), plaintext.length() + 1   );
    stfEncryptor.MessageEnd();



I did try to debug it, and the error pops right before the last return 0, I think while the class Destructor is being called the de-allocation is causing this issue?


Any help would be greatly appreciated.

解决方案

I found the solution myself; while compiling the source code of CryptoPP, in the solution properties(cryptdll), under C/C++ menu there is a sub-menu called Code Generation, the field Runtime Library should be Multi-threaded Debug DLL (/MDd). Thanks for your time guys. Farewell.


这篇关于Crypto ++,_ BLOCK_TYPE_IS_VALID错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆