I see a problem: in your decryptor, the IV is not initialized.
You have to decrypt with the same key and IV.
IV is not a secret; you may transmit it from the encryption to decryption
processes.
I am not sure why decryption worked for some smaller values.


On Mon, Feb 24, 2014 at 7:44 AM, Việt Hồ <[email protected]> wrote:

> Hello guys. I have some code of cryptoPP using AES algorithm. And it's
> work with some small .txt file but when i decrypt some big file (suck as
> .doc file) it doesn't work. But i don't understand how does it work. Please
> comment in each line in my project. Sorry because my English is not good.
> Thank you! And here is my code:
>
>
>
> void encryptFile(const char* password, const char* inputFileName,
>                  const char* outputFileName)
> {
>   byte pass[AES::BLOCKSIZE];
>   byte iv[16];
>
>   AutoSeededRandomPool rng;
>
>
>   StringSource(password, true,
>                new HashFilter(*(new SHA256), new ArraySink(pass,
> AES::BLOCKSIZE)));
>
>   rng.GenerateBlock(iv, 16);
>
>
>   AES::Encryption aesEncryption(pass, CryptoPP::AES::DEFAULT_KEYLENGTH);
>
>   CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv);
>
>
>   StreamTransformationFilter *encryptor;
>
>   encryptor = new StreamTransformationFilter(cbcEncryption,
>                                              new FileSink(outputFileName)
> );
>
>   encryptor->Put(iv, 16);
>
>
>   FileSource(inputFileName, true, encryptor);
>
> }
>
>
> void decryptFile(const char* password, const char*inputFileName,
>                  const char* outputFileName)
> {
>   byte pass[AES::BLOCKSIZE];
>   byte iv[16];
>
>   try {
>     StringSource(password, true, new HashFilter(*(new SHA256), new
>
> ArraySink(pass,AES::BLOCKSIZE)));
>
>     CryptoPP::AES::Decryption aesDecryption(pass,
> CryptoPP::AES::DEFAULT_KEYLENGTH);
>     CryptoPP::CBC_Mode_ExternalCipher::Decryption
> cbcDecryption(aesDecryption, iv);
>
>     StreamTransformationFilter *decryptor;
>
>     decryptor = new
>       StreamTransformationFilter(cbcDecryption, new
> FileSink(outputFileName));
>
>
>     char garbage[16], iv_garbage[16];
>     ifstream inf;
>     inf.open(inputFileName); inf.read(iv_garbage, 16);
>
>     cbcDecryption.ProcessData((byte *)garbage, (const byte *)iv_garbage,
> 16);
>
>     FileSource(inf, true, decryptor);
>
>     inf.close();
>   }
>   catch(CryptoPP::Exception &e)
>     {
>       cerr << "Caught exception during decryption!" << endl;
>       return;
>     }
> }
>
> --
> --
> 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.
>

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