Package: encr
encrMakes serializing safer and easier by encrypting your data with a custom password.
You can get a history of all added functionalities between updates in theCHANGELOG.mdfile.
You can get a list of features that should come in the future in theCOMING_SOON.MDfile.DependenciesThis package currently depends oncryptography, which at the time of writing depends oncffi, which again depends onpycparser.Summing up, along with this package other 3 will be installed:cryptographycffipycparserUsageTheencrclass: safe data encryption and serialization with custom passwordCreating anencrinstancefrom encr import encr
e = encr("Password")encrtakes two arguments:password, the string that will be hashed and converted into a key for encryptionclvl(optional), the compression level. Readzlib's documentationfor information about that.Changing the password mid-script:setkeye.setkey("New password")setkeychanges the key used for serialization. It takes one argument:password, the string that will be hashed and converted into a key for encryptionWarningRemember: changing the password of anencrinstance will make all previously encrypted data unusable, until you create another instance with the original password or reset the existing one withsetkey.Changing the compression level mid-scripte.clvl = 5clvlis an attribute, which means it is a variable and it can't be called as a function. Just sete.clvllike a normal variable.Encrypting and decrypting:dumpsandloadsserialized_object = e.dumps("foobar")
print(serialized_object)b'gAAAAABj85Nfc5tnmOSwj_wlSvFUop-E5ifYmEQUa8n2Ld5cNw5mahzkA-OpBDA9ky21OJa7vcLfheRMKA4yJppp7_ot_bWyTJ9lU5-TXCaeSJO8hzy3T7Y='
deserialized_object = e.loads(serialized_object)
print(deserialized_object)
foobardumpsserializes the object. It takes one argument:obj, the object to be encryptedloadsdeserializes the object. It takes one argument:obj, the encrypted object to be deserializedSaving a variable to a file:dumpandloade.dump("foobar", "file.encr")
print(e.load("file.encr"))"foobar"dumpserializes the object and saves it in a file. It takes two arguments:obj, the object to be encryptedfile, the file where your object will be savedloadtakes a serialized object from a file and deserializes it. It takes one argument:file, the file where the object is storedEncrypting a file:dumpfileandloadfilee.dumpfile("MyFile.txt", "MyFile.encr")
e.loadfile("MyFile.encr", "MyFile.txt")dumpfilereads a file and serializes it's content. It takes two arguments:file, the file to be encrypteddest, where your serialized file is savedloadfilereads a file and deserializes it's content. It takes two arguments:file, the file to be decrypteddest, where your deserialized file is storedEncrypting a folder:dumptreeandloadtreee.dumptree("MyFolder", "MyFile.encr")
e.loadtree("MyFile.encr")dumptreereads all the files contained in a folder and in all it's subfolders and serializes both their content, name and position. It takes two arguments:file, the folder to be encrypteddest, the file where your serialized folder is savedloadtreereads a file and restores the serialized tree. It takes one argument:file, the file containing the treeChanging the password:setkeye = encr("Password")
e.setkey("Password2")You can change the key used for encryption anytime with thesetkeymethod.Miscellaneous:dumpfile,dumptreeandloade.dumptree("MyFolder", "MyData.encr")
print(e.load("MyData.encr")["MyFolder\\MyFile"].decode())You can encrypt a file withdumpfileor a tree withdumptreeand access it's content withloadwithout having to decrypt it.dumpfilesaves directly the file's contents in binary mode,dumptreesaves all the filepaths and the file's contents in a dictionary.