Hello All,
I encrypt a file using AES::CBC mode with a random IV. Something
like this
void encryptFile(const char* password, const char* inputFileName,
const char* outputFileName)
{
byte pass[ AES::BLOCKSIZE ]; // digest of password
byte iv[ AES::BLOCKSIZE ]; // Initial Vector (IV)
AutoSeededRandomPool *rng;
rng = new AutoSeededRandomPool; // random number generator
// digest password
delete new StringSource( password, true,
new HashFilter(*(new SHA256), new ArraySink(pass,
AES::BLOCKSIZE)) );
// random Initial Vector
rng->GenerateBlock(iv, AES::BLOCKSIZE);
// create object for encrypting
AES::Encryption aesEncryption(pass,
CryptoPP::AES::DEFAULT_KEYLENGTH);
CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption,
iv);
StreamTransformationFilter *encryptor;
encryptor = new StreamTransformationFilter(cbcEncryption, new
FileSink(outputFileName) );
// "bind" a file and encrypt one
delete new FileSource(inputFileName, true, encryptor);
}
Now how do I get the same Initialization Vector (IV) to decrypt the
encrypted file or how do I write the decryptFile function:
void decryptFile(const char* password, const char*inputFileName,const
char* outputFileName)
{
//how to get the IV that was used for encrypting the file.
byte pass[ AES::BLOCKSIZE ];
byte iv[ AES::BLOCKSIZE ];
FileSource *source;
try
{
source = new FileSource(inputFileName, false);
delete new 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 );
// "bind" decryptor to output file
source->Attach( new StreamTransformationFilter(cbcDecryption,
new FileSink((outputFileName) ) ));
// push the rest data
source->PumpAll();
}
catch(CryptoPP::Exception &e)
{
delete source ;
throw;
}
delete source ;
}
The above decryptFile function doesnt decrypt the first block. I dont
know why?
Please help.
Please help as this is really important to me.
Thanks
--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---