When using the pickle lib with some classes that i have created, the output is fairly easily readable to the user. For example, if i have a fill called saves, and save all my class data into a .save file inside it, when opening the file with a text editor, you can vaguely see all the variables and without too much struggle, change them to a desired result.
Heres a snippet from a save file i created with pickle (it's a game):
Instead of trying to make your data unreadable, you could simply sign the data and then authenticate it when read.
hmac to compute a hash. We then save the hash along with the data:
import hmac, pickle # pickle the data pickled = pickle.dumps(data) digest = hmac.new("some-shared-key", pickled, digestmod=<my choice of hasher> ).hexdigest() # now save the hashed digest and the pickled data with open("some-file", "wb") as f: # save these in some way you can distinguish them when you read them print(digest, file=f) print(pickled, file=f)
To authenticate the data we recompute the digest of the pickled data and compare it against the digest saved alongside it.
import hmac, pickle with open("some-file", "rb") as f: digest = f.readline() pickled = f.read() # confirm integrity recomputed = hmac.new("some-shared-key", pickle, digestmod=<my choice of hasher> ).hexdigest() if not compare_digest(digest, recomputed): raise SomeOneIsCheatingOhNoException