title: I keep getting Invalid Token error in python cryptography (cryptography.fernet.InvalidToken)
body: <p>I wrote this prototype code to encrypt some text (and vice - versa). I keep getting this error when I set the command to <code>self.get()</code> while <code>self.write</code> works as it should. I have no idea what causes this error or how to solve it...Help...</p>
  <pre><code>from cryptography.fernet import Fernet
  
  class EncodingText:
      def __init__(self):
          self.key = Fernet.generate_key()
          self.f = Fernet(self.key)
          self.get()
  
      def write(self):
          stuff = &quot;hello there&quot;.encode()
          token = self.f.encrypt(stuff)
          open_file_for_edit = open(&quot;file.txt&quot;, 'wb')
          open_file_for_edit.write(token)
          open_file_for_edit.close()
  
      def get(self):
          read_file = open(&quot;file.txt&quot;, 'rb')
          reading = read_file.read()
          print(reading)
          token = self.f.decrypt(reading)
          print(token)
          read_file.close()
  
  
  if __name__ == &quot;__main__&quot;:
      EncodingText()
  </code></pre>
  <p>The error I get is as follows:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\xoxo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cryptography\fernet.py&quot;, line 113, in _verify_signature
      h.verify(data[-32:])
    File &quot;C:\Users\xoxo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cryptography\hazmat\primitives\hmac.py&quot;, line 70, in verify
      ctx.verify(signature)
    File &quot;C:\Users\xoxo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cryptography\hazmat\backends\openssl\hmac.py&quot;, line 78, in verify
      raise InvalidSignature(&quot;Signature did not match digest.&quot;)
  cryptography.exceptions.InvalidSignature: Signature did not match digest.
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;c:/Users/xoxo/Desktop/Python Programs/xoxo/xoxo.py&quot;, line 26, in &lt;module&gt;
      EncodingText()
    File &quot;c:/Users/xoxo/Desktop/Python Programs/xoxo/xoxo.py&quot;, line 7, in __init__
      self.get()
    File &quot;c:/Users/xoxo/Desktop/Python Programs/xoxo/xoxo.py&quot;, line 20, in get
      tokenf = self.f.decrypt(reading)
    File &quot;C:\Users\xoxo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cryptography\fernet.py&quot;, line 76, in 
  decrypt
      return self._decrypt_data(data, timestamp, ttl, int(time.time()))
    File &quot;C:\Users\xoxo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cryptography\fernet.py&quot;, line 125, in _decrypt_data
      self._verify_signature(data)
    File &quot;C:\Users\xoxo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cryptography\fernet.py&quot;, line 115, in _verify_signature
      raise InvalidToken
  cryptography.fernet.InvalidToken
  </code></pre>