Вибачте, затупив
При "ab":
Traceback (most recent call last):
File "C:\Users\xxxl\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\fernet.py", line 106, in _verify_signature
h.verify(data[-32:])
File "C:\Users\xxxl\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\primitives\hmac.py", line 69, in verify
ctx.verify(signature)
File "C:\Users\xxxl\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\backends\openssl\hmac.py", line 73, in verify
raise InvalidSignature("Signature did not match digest.")
cryptography.exceptions.InvalidSignature: Signature did not match digest.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/d/illya/practice/practice/practic_x_1.py", line 22, in <module>
print(f.decrypt(file.read()).decode("UTF-8")) #вивожу на екран все що в документі
File "C:\Users\xxxl\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\fernet.py", line 75, in decrypt
return self._decrypt_data(data, timestamp, ttl)
File "C:\Users\xxxl\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\fernet.py", line 119, in _decrypt_data
self._verify_signature(data)
File "C:\Users\xxxl\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\fernet.py", line 108, in _verify_signature
raise InvalidToken
cryptography.fernet.InvalidToken
При "ab+" i "wb+" (помилка та ж сама):
Traceback (most recent call last):
File "D:/d/illya/practice/practice/practic_x_1.py", line 20, in <module>
print(f.decrypt(file.read()).decode("UTF-8"))
File "C:\Users\xxxl\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\fernet.py", line 74, in decrypt
timestamp, data = Fernet._get_unverified_token_data(token)
File "C:\Users\xxxl\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\fernet.py", line 94, in _get_unverified_token_data
raise InvalidToken
cryptography.fernet.InvalidToken
Як ввід завжди вказував "Eff1c".
Ось як виглядає прога з "wb+" чи "ab+":
from cryptography.fernet import Fernet
key = Fernet.generate_key()
f = Fernet(key)
l = f.encrypt(bytes(input(), encoding="UTF-8"))
file = open("C:/Users/xxxl/Desktop/eff1c.txt", 'wb+') #міняється тільки значення 'wb+' на 'ab+'
file.write(l)
print(f.decrypt(file.read()).decode("UTF-8"))
file.close()