Reputation: 381
i have text editor program that i want it to have a encryption option to encrypt the text i have wrote the encryption part so(this is part of it that encrypts:
key= hashlib.sha256(str.encode(textbox1,"utf-8")).digest()
e = AES.new(key,AES.MODE_EAX)
e1 = AES.new(key,AES.MODE_EAX)
ciphertext = e.encrypt(bytes(text.get(0.1,END),"utf-8"))
s=e1.decrypt(ciphertext)
text.delete(0.0,END)
text.insert(0.0,ciphertext)
print(s.decode())
#how do i convert e1.decrypt(ciphertext) to string that i can put into text later?
How do I convert e1.decrypt(ciphertext) to string that I can put into text later or how do I convert the encrypted bytes to string that i can save in a text file or see it in the text widget?
edit:I found the problem in eax mode it nonce to decrypt: e1 = AES.new(key,AES.MODE_EAX,e.nonce) but how can I store this nonce somehow nonebyte that it would show it tkinter text widget?
Upvotes: 2
Views: 522
Reputation: 112865
Typically is is not possible to convert the encrypted bytes to string since encryption produces non-character bytes. Usually if a printable string representation is needed Base64 or hexadedcimal is used.
Upvotes: 1