I was not able to encrypt with these parameters set to zero. You need 16 meaningful bytes in key and IV.
On Fri, Nov 1, 2013 at 7:08 AM, David Irvine,,, <[email protected]>wrote: > Alok Sethi writes: > > « HTML content follows » >> >> >> 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. >> > Apart from these stack errors, what are you trying to do, it seems you are > setting key and iv to zero, is this intentional. Should you not take a key > and iv in through your parameters and set these to the size of the > constants you have to create the key ivector. If you did want to create a > key and iv of zero then set each array member to zero, but it would be > quite strange. > > Apart from that you are setting one past the end of the byte array, the > end of an array size 64 is element 63. > >> >> >> 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; and >> iVector[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 <URL:javascript:>cryptopp- > >> [email protected]. >> > More information about Crypto++ and this group is available at > >> <URL:http://www.cryptopp.com>h**ttp://www.cryptopp.com<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 >> <URL:javascript:>cryptopp-**[email protected]<[email protected]> >> . >> > For more options, visit > <URL:https://groups.google.** >> com/groups/opt_out <https://groups.google.com/groups/opt_out>>https://** >> groups.google.com/g <https://groups.google.com/g> > roups/opt_out. >> >> >> >> -- >> -- >> You received this message because you are subscribed to the "Crypto++ >> Users" Google Group. >> To unsubscribe, send an email to cryptopp-users-unsubscribe@** >> googlegroups.com <[email protected]>. >> More information about Crypto++ and this group is available at <URL: >> http://www.cryptopp.com>h**ttp://www.cryptopp.com<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 >> cryptopp-users+unsubscribe@**googlegroups.com<cryptopp-users%[email protected]> >> . >> For more options, visit >> <URL:https://groups.google.**com/groups/opt_out<https://groups.google.com/groups/opt_out> >> >https://**groups.google.com/groups/opt_**out<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 cryptopp-users-unsubscribe@** > googlegroups.com <[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 > cryptopp-users+unsubscribe@**googlegroups.com<cryptopp-users%[email protected]> > . > For more options, visit > https://groups.google.com/**groups/opt_out<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.
