title: Python Cryptography Error with Decryption
body: <p>I am working on a piece of code which takes an input, writes it to a text file then reads the text file, decrypts it and prints the output. Everything is working except for the decrypt part of my code. I have two linescommented out above. They were also producing errors which led me to believe it is a problem with my decryption.</p>
  
  <pre><code>import cryptography
  from cryptography.fernet import Fernet
  import os
  import os.path
  
  doc = open("cryptest.txt", "a+")
  query = input('Type the text to be encrypted:').encode('utf-8')
  print(query + ' is the query'.encode('utf-8'))
  
  key = Fernet.generate_key()
  f = Fernet(key)
  cipher_text = f.encrypt(query)
  #plain_text = f.decrypt(query)
  #plain_text = f.decrypt(cipher_text)
  
  
  doc.write("\n" + str(cipher_text))
  doc.close() #closes file
  open1 = open("cryptest.txt", "r") #opens file to read it
  #open2 = open1.encode('utf-8')
  print(open1.read() + 'is the contents of the text document')
  #print (f.decrypt(open2.read())) #prints whatever is in the text file 
  plaint = open1.read().encode('utf-8')
  print(plaint +'is the encoded contents of the file'.encode('utf-8'))
  decrypto = f.decrypt(plaint)
  print(str(decrypto) + 'is the decrypted information'.encode('utf-8'))
  
  doc.close()
  </code></pre>
  
  <p>The error I am getting is as follows</p>
  
  <pre><code>Traceback (most recent call last):
  File ".\CryptoTut.py", line 25, in &lt;module&gt;
  decrypto = f.decrypt(plaint)
  File "C:\Program Files (x86)\Python36-32\lib\site- 
  packages\cryptography\fernet.py", line 74, in decrypt
  timestamp, data = Fernet._get_unverified_token_data(token)
  File "C:\Program Files (x86)\Python36-32\lib\site- 
  packages\cryptography\fernet.py", line 88, in _get_unverified_token_data
  raise InvalidToken
  cryptography.fernet.InvalidToken
  </code></pre>