加密功能中止错误 [英] Abort error in encryption function

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

问题描述

您好。我有这样的功能。但是有一个错误:R6010 - 中止被称为。任何人都可以帮我解决这个错误吗?

  void 加密( char  * pszFile, char  * pszSecret){
int size;
char * buf;
_bstr_t cipherText;
字符串名称;
ifstream in (pszFile,ios :: in | ios :: binary | ios ::酯);
ofstream out;
IAlgorithmPtr algo;
IEncryptedDataPtr encryptor;

if (!in.is_open())
cout<< szErrNoFile<<的std :: ENDL;

else {
size = in .tellg();

buf = new char [size + 1 ];
buf [size] = 0 ;

in .seekg( 0 ,ios :: beg);
.read(buf,size);
in .close();

encryptor.CreateInstance( CAPICOM.EncryptedData);
encryptor-> PutContent(_bstr_t(buf)); // 我认为错误就在这里

algo = encryptor-> GetAlgorithm ();
algo-> PutName(CAPICOM_ENCRYPTION_ALGORITHM_AES);
algo-> PutKeyLength(CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM);

encryptor-> SetSecret(_bstr_t(pszSecret),CAPICOM_SECRET_PASSWORD);

cipherText = encryptor->加密(CAPICOM_ENCODE_BASE64);

name = pszFile;
name.append( 。encrypted);
out.open(name.c_str(),ios :: out | ios :: binary);


if (!out.is_open())
cout<< szErrWrite<< ENDL;

else {
out<<密文;
out.close();
}
}
}

解决方案

这是一个不寻常的错误。在这种情况下,R6010是C库中的中止,MSVCRT。我会检查你的程序是否真的达到你指示的那条线。 (通过设置断点)如果是这样,那么你必须做一些严重的内存损坏。如果不是我的猜测,你会错误的库连接起来,你的程序在启动时失败了。除了在启动期间,通常不会看到R6010。你有没有篡改/ ENTRYPOINT或其他东西?

无论如何,如果它已达到你标记的点,确保 encryptor 被正确初始化所以你可以分配它并且不要使用BSTR,除非你绝对不得不,他们不知道什么是BeeStings。如果加密会增加数据的长度,你也可以尝试使用更大的缓冲区。

当你尝试了所有这些时,你可能已经发现了一些我错过的错误。

Hello. I have such function. But there is an error: "R6010 - abort has been called". Could anyone help me with this error?

void Encrypt (char *pszFile, char *pszSecret) {
	int size;
	char *buf;
	_bstr_t cipherText;
	string name;
	ifstream in (pszFile, ios::in | ios::binary | ios::ate);
	ofstream out;
	IAlgorithmPtr algo;
	IEncryptedDataPtr encryptor;

	if ( !in.is_open() )
		cout << szErrNoFile << std::endl;

	else {
		size = in.tellg();

		buf = new char[size + 1];
		buf[size] = 0;

		in.seekg(0, ios::beg);
		in.read(buf, size);
		in.close();
  
		encryptor.CreateInstance("CAPICOM.EncryptedData");
		encryptor->PutContent(_bstr_t (buf)); //I THINK ERROR IS HERE

		algo = encryptor->GetAlgorithm();
		algo->PutName(CAPICOM_ENCRYPTION_ALGORITHM_AES);
		algo->PutKeyLength(CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM);

		encryptor->SetSecret(_bstr_t (pszSecret), CAPICOM_SECRET_PASSWORD);

		cipherText = encryptor->Encrypt(CAPICOM_ENCODE_BASE64);

		name = pszFile;
		name.append(".encrypted");
		out.open(name.c_str(), ios::out | ios::binary);


		if ( !out.is_open() )
			cout << szErrWrite << endl;

		else {
			out << cipherText;
			out.close();
		}
	}
}

解决方案

That''s an unusual error. R6010 is an abort from the C library, MSVCRT in this case. I''d check that your program really gets as far as the line you''ve indicated. (by setting a breakpoint) If so then you must be doing some serious memory corruption. If not than my guess would be you''ve got the wrong libraries linked up and your program is failing on startup. Don''t usually see an R6010 except during startup. Have you doctored the /ENTRYPOINT or something?
Anyway if it is getting to the point you''ve marked make sure encryptor is initialised correctly so you can assign to it and don''t use BSTRs unless you absolutely have to, they''re not know as BeeStings for nothing. You could also try a larger buffer in case encryption is increasing the length of your data.
By the time you''ve tried all that you''ll probably have spotted some mistake that I missed.


这篇关于加密功能中止错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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