Package: pyflocker
PyFLockerPython Cryptographic (File Locking) LibraryLock as in Lock and Key.InstallationUsepiporpip3to install PyFLockerpip install pyflockerorpip3 install pyflockerIntroductionPyFLocker aims to be a highly stable and easy to use cryptographic library.
Before you read on, check if you agree to at least one of these points:PyCryptodome(x)andpyca/cryptographyhavevery differentpublic interfaces, which makes remembering all the imports
very difficult, and leaves you reading docs under deadline.The interface ofpyca/cryptographyis very difficult to use, let alone
remember the import:fromcryptography.hazmat.primitives.ciphers.algorithmsimportAESfromcryptography.hazmat.primitives.ciphersimportModes...fromcryptography.hazmat.backendsimportdefault_backend# and so on...You wish that only ifpyca/cryptographyhad been as easy to use asPycryptodome(x), it would have made life more easy.You sometimes think that the file encryption script you wrote were somehow
faster and played with both backends very well, but you weren't sure what to do.And all the other solutions (and nonsolutions!) on the internet just confuses
you more!PyFLocker uses well established libraries as its backends and expands upon them.
This gives you the ultimate ability to cherry-pick the primitives from a specific
backend without having to worry about backend itself, as PyFLocker handles it
for you.You can find more information in thedocumentation.FeaturesNot a "Yet Another Cryptographic Library"PyFLocker provides you a seamless interface to both the backends, and switching
is very easy:importosfrompyflocker.ciphersimportAES,RSA,ECCfrompyflocker.ciphers.backendsimportBackendskey,nonce=os.urandom(32),os.urandom(16)# Multiple backends - same APIenc=AES.new(True,key,AES.MODE_EAX,nonce,backend=Backends.CRYPTOGRAPHY)rpriv=RSA.generate(2048,backend=Backends.CRYPTODOME)epriv=ECC.generate("x25519",backend=Backends.CRYPTOGRAPHY)Backend loading is done internally, and if a backend is explicitly specified,
that is used as the default.Ease of UsePyFLocker provides reasonable defaults wherever possible:frompyflocker.ciphersimportRSApriv=RSA.generate(2048)withopen("private_key.pem","xb")asf:key=priv.serialize(passphrase=b"random-chimp-event")f.write(key)Don't believe me, try to do thesame operation withpyca/cryptography,
or just any other initialization.In short, the API is very stable, clear and easy on developer's mind.Writing into file or file-like objectsThis is often a related problem when it comes to encryption, but think no more!importosfrompyflocker.ciphersimportAESfrompyflocker.ciphers.backendsimportBackendskey,nonce=os.urandom(32),os.urandom(16)f1=open("MySecretData.txt","rb")f2=open("MySecretData.txt.enc","xb")enc=AES.new(True,key,AES.MODE_EAX,nonce,backend=Backends.CRYPTOGRAPHY,file=f1,)enc.update_into(f2)tag=enc.calculate_tag()You can also useBytesIOin place of file objects.Directly encrypting filesJust want to encrypt your file with AES, and even with various available modes?frompyflocker.lockerimportlockerfrompyflocker.ciphersimportAESpassword=b"no not this"locker("./MySuperSecretFile.txt",password,aes_mode=AES.MODE_CTR,# default is AES-GCM-256)# file stored as MySuperSecretFile.txt.pyflkFind more exampleshere.LicenseMIT