好日子,密碼解密失敗
我有一個劇本我創建,讀取用戶輸入,並將其與保存在一個文本文件中的關鍵。即使字符串是相同的,請幫助我:
from Crypto.Cipher import AES
from tkinter import *
#create the window
root = Tk()
#modify root window
root.title("Button Example")
#root.geometry("500x500")
app = Frame(root)
key='Key is unique!!!'
IV='This is an IV456'
#password=b'\xa3Y\x00\xae\xad\xad\x1c\xc6Js\xa9\xf4\x0e\xf3\x0f\xe3'
def encrypt():
obj = AES.new(key, AES.MODE_CBC, IV)
messagein = inputbar.get()
inputbar.delete(0,END)
messlen = len(messagein)
if messlen < 16:
diff = 16-messlen
message = 'z'*diff + messagein
global ciphertext
ciphertext = obj.encrypt(message)
print(ciphertext)
del obj
def check():
encrypt()
passwordfunc()
if ciphertext == password:
print('Success!')
else:
print('Fail!')
def passwordfunc():
file=open("E536D.dat","r")
global password
password = file.readline()
file.close()
print(password)
inputbar = Entry(root,font='TkDefaultFont 30')
inputbar.pack()
button1= Button(text='Encrpyt',command=lambda:encrypt())
button1.pack()
button2 = Button(text='Compare',command=lambda:check())
button2.pack()
button3 = Button(text='File',command=lambda:passwordfunc())
button3.pack()
root.mainloop()
我做了什麼錯了?行#password=b'\xa3Y\x00\xae\xad\xad\x1c\xc6Js\xa9\xf4\x0e\xf3\x0f\xe3'
是它需要比較的關鍵,但它從文件比較中返回false,但在它自己內部工作。請幫幫我。我通過移動obj = AES.new(key, AES.MODE_CBC, IV)
來加密和刪除函數結尾處的不同密鑰輸出。但是,當我比較文件中的字符串和正確的輸入python仍然說他們不一樣。下面是我的意思的截圖。
這個鍵和IV必須有16個字符,並且要被描述的文本必須是16個字符的倍數,如果它不是 –
那麼我必須填充一些像空格這樣的字符。 :'if messlen <16: diff = 16-messlen message ='z'* diff + messagein' –
「E536D.dat」是一個二進制文件,包含_just_那些字節,沒有換行符?如果是這樣,你應該以二進制模式打開它,並使用'.read()'方法來獲取字節數據。如果不是,您應該向我們展示其內容的十六進制轉儲,以便我們瞭解如何正確讀取它。 –