Skip to content

coal0/Locker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Locker 🔒

A place to keep your valuables.


Locker makes it easy to securely store data in a key:value scheme on a hard drive.
Locker is only compatible with Python 3 and upwards and requires the cryptography library.


Locker is now on PyPi.org! Install with:

pip install python-locker
NOTE: You may need to replace pip with pip3, if available.

Quick start

Each locker represents a storage space (file) encrypted using a separate password. To get started, just import the Locker class:

>>> from locker import Locker

Assuming you don't have a locker yet, create a new one with Locker.create_locker.
Be sure to pass a bytes object as the password argument.

>>> Locker.create_locker(
...     path="foo",
...     password=b"bar"
... )
NOTE: Creating a new vault or opening an existing one may take some time, because the password storage algorithms require lots of computational power. Please be patient.

Now that your locker has been created, you can load it:

>>> locker = Locker(
...     path="foo",
...     password=b"bar"
... )

To open the locker and decrypt its contents, call Locker.open.
To demonstrate what happens when you enter a wrong password, let's modify the password attribute:

>>> locker.password
b'bar'
>>> locker.password = b'spam'
>>> locker.open()
Traceback (most recent call last):
...
cryptography.exceptions.InvalidKey: invalid password provided

As you can see, a cryptography.exceptions.InvalidKey exception is raised.
Let's restore the original password and try opening the locker again:

>>> locker.password = b'foo'
>>> locker.open()

The open call should return with no traceback.


With the locker being opened, let's take a look at its contents:

>>> locker.contents
{}

Our locker is empty, but we can change that.
You can manually add key:value entries to the locker, or use the convenient get, set and delete methods:

>>> locker.set(b"foo", b"bar")
>>> locker.get(b"foo")
b'bar'
>>> locker.delete(b"foo")
>>> locker.get(b"foo")
Traceback (most recent call last):
...
KeyError: "key b'foo' not in locker"

Note especially how all key:value pairs are bytes objects.


To save any changes you made, call close:

>>> locker.close()

Don't forget to call this method after you're done modifying a locker, or your changes will be discarded.