好日子,密码解密失败
我有一个剧本我创建,读取用户输入,并将其与保存在一个文本文件中的关键。即使字符串是相同的,请帮助我:
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()'方法来获取字节数据。如果不是,您应该向我们展示其内容的十六进制转储,以便我们了解如何正确读取它。 –