Skip to content

encrypt, decrypt, and verify pickled objects

License

Notifications You must be signed in to change notification settings

0x42069420/protected

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

from protected import dump, load, generate_fernet_key

class Example:
    secret = "secretsecretigotasecret"
    data = { "a":1, "b":2, "c":3 }
    def get_data(self, key:str) -> int: return self.data[key]

ex = Example()

print(ex.get_data("a"), ex.get_data("b"), ex.get_data("c"))

fernet_key = generate_fernet_key()

with open("example.pkl", "wb") as file: 
    digital_signature = dump(fernet_key, ex, file)

with open("example.pkl", "rb") as file: 
    new_ex = load(fernet_key, digital_signature, file)

print(new_ex.get_data("a"), new_ex.get_data("b"), new_ex.get_data("c"))