title: Trying to encrypt
body: <p>Disclaimer: I'm not that good at python so sorry if this is some simple problem I cant see.</p>
  
  <p>Basically I wanted to make a login and sign up system that stores the username and password in a text file, then I want to encrypt the data in that file. I've never done encryption before so I took the code from online for the login and sign up system to test and try it out. I got tons of errors that i have never seen before so I just want some help. I have not done the decryption yet(if that even matters). Sorry if i pasted too much I just have no clue how to fix this. The encryption part is the def Encryption(): and I implement it in def FSSignup():.</p>
  
  <pre><code>from cryptography.fernet import Fernet
  from tkinter import *
  import os
  
  creds = 'tempfile.temp' #
  
  def Signup():
      global pwordE
      global nameE
      global roots
  
      roots = Tk()
      roots.title('Signup')
      intruction = Label(roots, text='Please Enter new Credidentials\n')
      intruction.grid(row=0, column=0, sticky=E)
  
      nameL = Label(roots, text='New Username: ')
      pwordL = Label(roots, text='New Password: ')
      nameL.grid(row=1, column=0, sticky=W)
      pwordL.grid(row=2, column=0, sticky=W)
  
      nameE = Entry(roots)
      pwordE = Entry(roots, show='*')
      nameE.grid(row=1, column=1)
      pwordE.grid(row=2, column=1)
  
      signupButton = Button(roots, text='Signup', command=FSSignup)
      signupButton.grid(columnspan=2, sticky=W)
      roots.mainloop()
  
  def Encryption():
      file = open('Encryption.txt', 'rb' )
      key = file.read()
      file.close()
  
      with open('tempfile.temp', 'rb') as f:
          data = f.read()
  
      fernet = Fernet(key)
      encrypted = fernet.encrypt(data)
  
      with open('tempfile.temp.encrypted', 'wb') as f:
          f.write(encrypted)
  
  def FSSignup():
      with open(creds, 'w') as f:
          f.write(nameE.get())
          f.write('\n')
          f.write(pwordE.get())
          f.close()
  
      Encryption()
      roots.destroy()
      Login()
  
  def Login():
      global nameEL
      global pwordEL
      global rootA
  
      rootA = Tk()
      rootA.title('Login')
  
      intruction = Label(rootA, text='Please Login\n')
      intruction.grid(sticky=E)
  
      nameL = Label(rootA, text='Username: ')
      pwordL = Label(rootA, text='Password: ')
      nameL.grid(row=1, sticky=W)
      pwordL.grid(row=2, sticky=W)
  
      nameEL = Entry(rootA)
      pwordEL = Entry(rootA, show='*')
      nameEL.grid(row=1, column=1)
      pwordEL.grid(row=2, column=1)
  
      loginB = Button(rootA, text='Login', command=CheckLogin)
      loginB.grid(columnspan=2, sticky=W)
  
      rmuser = Button(rootA, text='Delete User', fg='red', command=DelUser)
      rmuser.grid(columnspan=2, sticky=W)
      rootA.mainloop()
  
  def CheckLogin():
      with open(creds) as f:
          data = f.readlines()
          uname = data[0].rstrip()
          pword = data[1].rstrip()
  
      if nameEL.get() == uname and pwordEL.get() == pword:
          r = Tk()
          r.title(':D')
          r.geometry('150x50')
          rlbl = Label(r, text='\n[+] Logged In')
          rlbl.pack()
          r.mainloop()
      else:
          r = Tk()
          r.title('D:')
          r.geometry('150x50')
          rlbl = Label(r, text='\n[!] Invalid Login')
          rlbl.pack()
          r.mainloop()
  
  def DelUser():
      os.remove(creds)
      rootA.destroy()
      Signup()
  
  if os.path.isfile(creds):
      Login()
  else: 
      Signup()
  </code></pre>
  
  <p>Here are the errors I have no clue what are.</p>
  
  <p>Exception in Tkinter callback:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):
      File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\tkinter__init__.py", line 1702, in <strong>call</strong>
        return self.func(*args)</p>
    
    <p>File "C:\Users\admin\Desktop\Py1A\SignUpSystem\Thing123.py", line 52, in FSSignup
        Encryption()</p>
    
    <p>File "C:\Users\admin\Desktop\Py1A\SignUpSystem\Thing123.py", line 39, in Encryption
        fernet = Fernet(key)</p>
    
    <p>File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\cryptography\fernet.py", line 35, in <strong>init</strong>
        key = base64.urlsafe_b64decode(key)</p>
    
    <p>File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\base64.py", line 133, in urlsafe_b64decode
        return b64decode(s)</p>
    
    <p>File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\base64.py", line 87, in b64decode
        return binascii.a2b_base64(s)</p>
    
    <p>binascii.Error: Incorrect padding</p>
  </blockquote>
  
  <p>This happens right after I sign up and it attempts to encrypt the new username and password.</p>