title: What is the difference between FileSink, StringSink, Filesource, StringSource Crypto++
body: <p>I am reading in an image, encrypting it, then decrypting it. The goal is to be looping this eventually and recording the time it takes for the process to complete. Currently what I have it reads the file in, then it encrypts it, encrypts it, the creates another file based on the recovered data. I don't need to make another file with the decrypted picture. Previously I had been using <code>StringSource</code> and <code>StringSink</code>, but that only worked for text files. I received some help at <a href="https://stackoverflow.com/questions/23354548/how-to-read-an-image-to-a-string-for-encrypting-crypto/23355279#23355279">How to read an image to a string for encrypting Crypto++</a> from and started using <code>FileSink</code> and <code>FileSource</code>. </p>
  
  <p>What exactly is the difference between <code>FileSink</code>, <code>StringSink</code>, <code>FileSource</code> and <code>StringSource</code> ?</p>
  
  <p>Also, in following example, why does cipher need to be set to something? Previously when I was just using <code>StringSource</code>, my string cipher was not initialized, but now that I am using <code>FileSource</code>, it needs to be initialized for it to work.</p>
  
  <pre><code>int main(int argc, char* argv[])
  {
      AutoSeededRandomPool prng_blowfish;
  
      SecByteBlock key_blowfish(Blowfish::DEFAULT_KEYLENGTH);
      prng_blowfish.GenerateBlock(key_blowfish, key_blowfish.size());
  
      byte iv_blowfish[Blowfish::BLOCKSIZE];
      prng_blowfish.GenerateBlock(iv_blowfish, sizeof(iv_blowfish));
  
      string ifilename = "sample_files/1MB.jpg";
      string cipher = "1MB.enc";
      string rfilename = "r1MB.jpg";
  
      try
      {
          EAX&lt;Blowfish&gt;::Encryption e_blowfish;
          e_blowfish.SetKeyWithIV(key_blowfish, key_blowfish.size(), iv_blowfish, sizeof(iv_blowfish));
  
          std::ifstream ifile(ifilename.c_str(), ios::binary);
          std::ifstream::pos_type size = ifile.seekg(0, std::ios_base::end).tellg();
          ifile.seekg(0, std::ios_base::beg);
  
          FileSource fs1(ifilename.c_str(), true, new AuthenticatedEncryptionFilter(e_blowfish, new FileSink(cipher.c_str())));
  
          EAX&lt;Blowfish&gt;::Decryption d_blowfish;
          d_blowfish.SetKeyWithIV(key_blowfish, key_blowfish.size(), iv_blowfish, sizeof(iv_blowfish));
  
          FileSource fs2(cipher.c_str(), true, new AuthenticatedDecryptionFilter(d_blowfish, new FileSink(rfilename.c_str()), AuthenticatedDecryptionFilter::THROW_EXCEPTION));
      }
      catch (const Exception&amp; ex)
      {
          cerr &lt;&lt; ex.what() &lt;&lt; endl;
      }
  
      return 0;
  }
  </code></pre>