title: pyAesCrypt crypt dictionary, save cipher text to file then read file and decrypt
body: <p>So I am trying to encrypt a dictionary and save it as cypher text, then open and decrypt the file so my program can use the passwords.<br />
  I do not want to save the decrypted file and it should only be stored in a variable.</p>
  <p>My current .py is as follows:</p>
  <pre><code>import io
  import json
  import pyAesCrypt
  
  
  password = 'some_password'
  bufferSize = 64 * 1024
  
  
  def enc():
      loaded_settings = {'pass1': 'xxx',
                         'pass2': 'ccc',
                         'key': 'ddd',
                         'secret': 'sss'}
  
      # binary data to be encoded
      user_encode_data = json.dumps(loaded_settings).encode('utf-8')
  
      # input plaintext binary stream
      fIn = io.BytesIO(user_encode_data)
  
      # initialize ciphertext binary stream
      fCiph = io.BytesIO()
  
      # encrypt stream
      pyAesCrypt.encryptStream(fIn, fCiph, password, bufferSize)
  
      # print encrypted data
      print(&quot;This is the ciphertext:\n&quot; + str(fCiph.getvalue()))
      with open(&quot;Output.txt&quot;, &quot;w&quot;) as text_file:
          text_file.write(str(fCiph.getvalue()))
  
  
  def dec():
      with open(&quot;Output.txt&quot;, &quot;r&quot;) as text_file:
          cipher_text = text_file
          fCiph = io.BytesIO(cipher_text.read().encode())
      # get ciphertext length
      ctlen = len(fCiph.getvalue())
  
      # go back to the start of the ciphertext stream
      fCiph.seek(0)
  
      # initialize decrypted binary stream
      fDec = io.BytesIO()
  
      # decrypt stream
      pyAesCrypt.decryptStream(fCiph, fDec, password, bufferSize, ctlen)
  
      # print decrypted data
      print(&quot;Decrypted data:\n&quot; + str(fDec.getvalue()))
  
      # decrypted data back as dict
      output_dict = json.loads(fDec.getvalue())
  
      print(output_dict['pass1'])
  
  
  enc()
  dec()
  </code></pre>
  <p>I am getting the error <code>ValueError: File is corrupted or not an AES Crypt (or pyAesCrypt) file.</code><br />
  Is there something wrong with the way I am opening the cypher text?</p>