Ok for a while I forget about perl script.

Here is a basic question about encryption/decryption.

I encrypt a file with AES::CBC mode using a random IV( Initialization Vector ). Now how do I get back the same IV for decrypting the encrypted file?

If I use my defined hard coded IV I'm able to decode the file with no problem (as I know what the IV is) but I want to use a random IV to encrypt a file and then want to decrypt the encrypted file.

The pseudo can is something like this

Qt Code:
  1. void encryptFile( const char* password, const char* inFile, const char* outFile)
  2. {
  3. //Get random IV named iv
  4. //Digest the password named pass
  5. AES::Encryption aesEncryption(pass, CryptoPP::AES::DEFAULT_KEYLENGTH);
  6. CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv);
  7. //Encrypt the file
  8. }
  9.  
  10. void decryptFile( const char* password, const char* inFile, const char* outFile)
  11. {
  12. //Now to decrypt the encrypted file I need to have the same IV
  13. // with which the file was encrypted to decrypt it.
  14. //I dont know how to get it
  15.  
  16. //Get the IV from the encrypted file
  17. //digest the password
  18. //Finally decrypt the encrypted file.
  19.  
  20. }
To copy to clipboard, switch view to plain text mode 

In the above code I dont know how to get the same IV by which the file was encrypted. Any idea?

If possible please give your answers taking crypto++ library in view.

Thanks.