Skip to content
Advertisement

How do I encrypt and decrypt files with Python fernet without getting TokenError?

I’m trying to make a login program that encrypts the login file when it’s not in use. The program keeps raising “InvalidToken” error. Does anyone know how to fix this? There might be some other problems with the code, so if you find any, please let me know as well. My code is below. I didn’t use all of the imported modules, but I have them there for later.

JavaScript

Advertisement

Answer

Your code works just fine, the problem is that you try to decrypt an empty file then verify its authenticity. so you need to create this file and try to encrypt any thing into this file then you can decrypt this file back again.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement