does a string you decrypt with fernet have to be in byte code

38 Views Asked by At

I am making a password manager using fernet in python i can add and encrypt passwords but cannot decrypt as I keep getting this error.

Traceback (most recent call last):
  File "/workspaces/big-schoolwork-repo/password manager/cli/password manager/main.py", line 251, in <module>
    main(edit, key)
  File "/workspaces/big-schoolwork-repo/password manager/cli/password manager/main.py", line 242, in main
    exploring(key)
  File "/workspaces/big-schoolwork-repo/password manager/cli/password manager/main.py", line 159, in exploring
    decrypted_passwords = decrypt_list(password_list, key)
  File "/workspaces/big-schoolwork-repo/password manager/cli/password manager/main.py", line 31, in decrypt_list
    decrypted_value = f.decrypt(encrypted_value.encode()).decode()
  File "/home/codespace/.local/lib/python3.10/site-packages/cryptography/fernet.py", line 86, in decrypt
    timestamp, data = Fernet._get_unverified_token_data(token)
  File "/home/codespace/.local/lib/python3.10/site-packages/cryptography/fernet.py", line 122, in _get_unverified_token_data
    raise InvalidToken
cryptography.fernet.InvalidToken

After some debugging I have discovered that it is possible that the error is because the thing i want to decrypt is not in byte string. All my passwords and account details are stored in a txt. here is a basic version.

youtube|b'gAAAAABlH9gZ2Msbp5JM0PdC5qPFw_NUvOGg3U785CWjoFBf7hdsOpVbp1tPSUC0KBrR3PgXrJucz7VYmQUYo2bVARljCYBXvA=='|b'gAAAAABlH9gccrUj0ggd4LcdgA2H-kirnQGchys3J4NbJXkOIAdGLKPBG7EqP0rk-szg9mmA28yGoIHl9dYu4eUxUOSDrG9gWw=='|b'gAAAAABlH9gk7AExnyYTkwHcJAuaB91LCfoKFpby8VatAdJIQBosdX7XMJ9vojUpkiS6aCgcNt-ynR2HEmrlC6swGp9vMKlpvQ=='
netflix|b'gAAAAABlH9hTV2lnLNAwVPgAcuPEIDdf-VgfIBiTW8UoNnBlwTMqJs8S5C6rmMHd2LjhTV4HHNrUWkoxeDZLnQxa5I1WksyATg=='|b'gAAAAABlH9hZCRz0m15Npk2dtrOuqC64Ega7XkmtrtGv3VOXRFnNYs10kvoiLc2dn4pk-35nU6SPnbsD9xnAr3-8bvH4sppTLQ=='|b'gAAAAABlH9hhqnrhzxgnlEPSMg3hlR8NOp-b_qFgzSfqtwoA4g8cyxYyXq11Z2DGTh_fGXr3KUpq0Au_bZrl1dvL3aL934BCPQ=='

it goes name of service, username, email, password. seperated by a "|". to get these values in my script i put it all in a 2d list with a separate list per row. However i cannot find a way to remove the "" around the valuse which stops it becoming a byte string. as this is what i get

[['youtube', "b'gAAAAABlH9gZ2Msbp5JM0PdC5qPFw_NUvOGg3U785CWjoFBf7hdsOpVbp1tPSUC0KBrR3PgXrJucz7VYmQUYo2bVARljCYBXvA=='", "b'gAAAAABlH9gccrUj0ggd4LcdgA2H-kirnQGchys3J4NbJXkOIAdGLKPBG7EqP0rk-szg9mmA28yGoIHl9dYu4eUxUOSDrG9gWw=='", "b'gAAAAABlH9gk7AExnyYTkwHcJAuaB91LCfoKFpby8VatAdJIQBosdX7XMJ9vojUpkiS6aCgcNt-ynR2HEmrlC6swGp9vMKlpvQ=='"], ['netflix', "b'gAAAAABlH9hTV2lnLNAwVPgAcuPEIDdf-VgfIBiTW8UoNnBlwTMqJs8S5C6rmMHd2LjhTV4HHNrUWkoxeDZLnQxa5I1WksyATg=='", "b'gAAAAABlH9hZCRz0m15Npk2dtrOuqC64Ega7XkmtrtGv3VOXRFnNYs10kvoiLc2dn4pk-35nU6SPnbsD9xnAr3-8bvH4sppTLQ=='", "b'gAAAAABlH9hhqnrhzxgnlEPSMg3hlR8NOp-b_qFgzSfqtwoA4g8cyxYyXq11Z2DGTh_fGXr3KUpq0Au_bZrl1dvL3aL934BCPQ=='"]]

Any suggestions on how to turn these into byte strings

0

There are 0 best solutions below