Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Errors cryptography
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();
		}
	}
}
Posted 1-Feb-13 7:47am
Comments
jibesh at 1-Feb-13 13:55pm
   
are you sure you have downloaded the Platform SDK with this 'Capicom.dll' and registered in your PC?
 
Read this article

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100