title: (Crypto++) How to realize media file encryption?
body: <p>I am new to Crypto++ and want to "convert" the text encryption code I found online to a Crypto++ file encryption. Basically, an image file is just a bunch of text which needs to be read in chunks, am I right?</p>
  
  <p>I want to read an image file and encrypt it with <em>CryptoPP::AES</em>:</p>
  
  <pre><code>void encryptImage(std::filesystem::path const&amp; file) {
      std::ifstream inpf(file.string().c_str(), std::ios::binary);
  
      CryptoPP::AutoSeededRandomPool rnd;
      int keyLength = CryptoPP::AES::DEFAULT_KEYLENGTH; // 16 bytes = 128 bit key
      int defBlockSize = CryptoPP::AES::BLOCKSIZE;
      // Generate a random key
      CryptoPP::byte key[CryptoPP::AES::DEFAULT_KEYLENGTH];
      rnd.GenerateBlock(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
  
      // Generate a random IV
      CryptoPP::byte iv[CryptoPP::AES::BLOCKSIZE];
      rnd.GenerateBlock(iv, CryptoPP::AES::BLOCKSIZE);
  
      char plainText[] = "Hello! How are you.";
      int messageLen = (int)strlen(plainText) + 1;
  
      //encrypt
      CryptoPP::CFB_Mode&lt;CryptoPP::AES&gt;::Encryption cfbEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH, iv);
      cfbEncryption.ProcessData((CryptoPP::byte*)plainText, (CryptoPP::byte*)plainText, messageLen);
  }
  </code></pre>
  
  <p>If I understand this code right it sets a random key and a random IV (don't know what that's supposed to mean) and uses the <em>CFB_MODE::Encryption</em> method to encrypt the given text from the <em>plainText</em> variable.</p>
  
  <p>My question is now... how can I change this code up so that it encrypts the file I am giving as parameter and reading in with <em>std::ifstream</em> instead of the text?</p>