Hi Fraser,

Thanks for your quick reply. As per your suggestion I tried by removing 
these two lines. But getting the same error message.
Also I tried to set the memory to zero as below.

memset( key, 0x01, CryptoPP::AES::DEFAULT_KEYLENGTH );
memset( iVector, 0x01, CryptoPP::AES::BLOCKSIZE );

It would be great if you could suggest any other alternative solutions. 


Thanks,
Alok.

On Friday, November 1, 2013 1:23:32 AM UTC+5:30, Fraser wrote:
>
>  Hi there,
>
> The cause of this error is where you have key[sizeof(key)] = 0; 
> andiVector[sizeof(iVector)] = 0; in 
> each of your functions.  You're trying to access an element one past the 
> end of each array.
>
> I guess you're trying to null-terminate these arrays, but there's no need 
> here.  In fact, it's valid for either the key or IV to contain '0' char(s) 
> anywhere within.
>
> Cheers,
> Fraser.
>
>
>
> On 31/10/2013 14:03, Alok Sethi wrote:
>  
> Hi,
>
> I want to encrypt and decrypt file contains using AES::CBC mode. I tried 
> the following for encryption and decryption.
> It works fine but I get the below two exceptions.
>
> 1. Run-Time Check Failure #2 - Stack around the variable 'iVector' was 
> corrupted.
> 2. Run-Time Check Failure #2 - Stack around the variable 'key' was 
> corrupted.
>
> I don't know exactly where I am doing wrong. Please help me to fix this 
> problem.
>
> To encrypt the file here is my code :-
> ==================================
> void Encrypt(string inFileName, string outFileName)
> {
>
>     byte key[CryptoPP::AES::DEFAULT_KEYLENGTH];
>     key[sizeof(key)] = 0;
>
>     byte iVector[CryptoPP::AES::BLOCKSIZE];
>     iVector[sizeof(iVector)] = 0;
>     
>     ifstream in(inFileName.c_str(), ios::binary);
>
>     const string orgStrObj((istreambuf_iterator<char>(in)), 
> istreambuf_iterator<char>());
>     in.close();
>     
>     CryptoPP::AES::Encryption cipher(key, sizeof(key));
>     
>     CryptoPP::CBC_Mode_ExternalCipher::Encryption encryption(cipher, 
> iVector);
>     CryptoPP::StreamTransformationFilter strFilter(encryption, new 
> CryptoPP::StringSink(encryptStr));
>     strFilter.Put(reinterpret_cast<const byte*>(orgStrObj.c_str()), 
> orgStrObj.size());
>     strFilter.MessageEnd();
>     
>      ofstream out(outFileName.c_str(), ios::binary);
>     out.write(encryptStr.c_str(), encryptStr.size());
>     out.close();
> }
>
>
> To decrypt the file here is my code :-
> ================================
> void Crypto::Decrypt(string inFileName, string outFileName)
> {
>     byte key[CryptoPP::AES::DEFAULT_KEYLENGTH];
>     key[sizeof(key)] = 0;
>
>     byte iVector[CryptoPP::AES::BLOCKSIZE];
>     iVector[sizeof(iVector)] = 0;
>     
>     ifstream in(inFileName.c_str(), ios::binary);
>
>     const string encryptStrObj((istreambuf_iterator<char>(in)), 
> istreambuf_iterator<char>());
>     in.close();
>   
>     CryptoPP::AES::Decryption cipher(key, sizeof(key));
>
>     CryptoPP::CBC_Mode_ExternalCipher::Decryption decryption(cipher, 
> iVector);
>     CryptoPP::StreamTransformationFilter strFilter(decryption, new 
> CryptoPP::StringSink(decryptStr));
>     strFilter.Put(reinterpret_cast<const byte*>(encryptStrObj.c_str()), 
> encryptStrObj.size());
>     strFilter.MessageEnd();
>     
>     ofstream out(outFileName.c_str(), ios::binary);
>     out.write(decryptStr.c_str(), decryptStr.size());
>     out.close();
> }
>  -- 
> -- 
> You received this message because you are subscribed to the "Crypto++ 
> Users" Google Group.
> To unsubscribe, send an email to 
> [email protected]<javascript:>
> .
> More information about Crypto++ and this group is available at 
> http://www.cryptopp.com.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Crypto++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>  

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to