1

I keep getting this error but cant find any helpful information on it. i am not storing it in a file but instead storing it in the decryption code so that no one can see it once it is compiled (if there is a better way of storing the key let me know please).

here is the error

get_data = ast.literal_eval(Fernet(Key).decrypt((Message).encode('utf-8')).decode('utf-8'))
  File "C:\Program Files\Python37\lib\site-packages\cryptography\fernet.py", line 38, in __init__
    "Fernet key must be 32 url-safe base64-encoded bytes."
ValueError: Fernet key must be 32 url-safe base64-encoded bytes.

here is my section of code

Key = b'pT8ZDjwCvnWkfPEYBm12q2p9srNkM-nWC6Ss9aAcMEw='

i made the code a bit easier to read

message_to_decrypt = (message_to_decrypt).encode('utf-8')
ast.literal_eval(Fernet(Key).decrypt(message_to_decrypt ).decode('utf-8'))
Connor
  • 114
  • 1
  • 11

1 Answers1

2

Try this

import base64

key = b'pT8ZDjwCvnWkfPEYBm12q2p9srNkM-nWC6Ss9aAcMEw='

key = base64.urlsafe_b64encode(key)

If this does not work provide the sample code that give you the error

Alex Duran
  • 44
  • 3