Skip to main content

Persistent Crypto Dictionary

This class implements a persistent dictionary using sqlite3 and encrypts the keys and the values of the dictionary in a way, that makes it very hard to bruteforce either the key or the values in the db.

example usage::
>>> from pcd import PersistentCryptoDict
>>> d=PersistentCryptoDict()
>>> print d
<pcd.PersistentCryptoDict instance at 0x8dcb54c>
>>> print d['my key']
None
>>> d['my key']='secret value'
>>> print d['my key']
secret value
>>> d['my key']='top secret value'
>>> print d['my key']
top secret value

Crypto

The key and the value in the dict is transformed according to the following algorithm (credit: dnet):

Setting values

  1. we calculate they keyhash - a hmac-sha512(salt,key)

  2. we split the key in half, the first half as a hexdigest (ascii), the second we keep as a binary

  3. we use the second binary half from step 2 of the keyhash to encrypt the value

  4. we use the ascii keyhash from step 2 as a key to the database, and the value is the encrypted result from step 3.

Getting values

  1. we calculate they keyhash - a hmac-sha512(salt,key)

  2. we split the key in half, the first half as a hexdigest (ascii), the second we keep as a binary

  3. we query the database using the ascii keyhash from step 2 as a key

  4. we use the second binary half from step 2 of the keyhash to decrypt the value

The database contains only the following pairs of data:

(hmac-sha512(key, salt).hexdigest()[:64], # key aes256-ofb(hmac-sha512(key, salt).digest()[32:], value)) # value

we diligently obey Schneier’s law: https://www.schneier.com/blog/archives/2011/04/schneiers_law.html, and thus we would consider the task to retrieve any meaningful data without huge rainbow tables from such a database a futile task. :)

Metadata

Release files for persistent-crypto-dict 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for persistent-crypto-dict 0.5.0
File Size Uploaded Provenance
persistent_crypto_dict-0.5.0.tar.gz 4.1 kB Without provenance Details

Release files / persistent_crypto_dict-0.5.0.tar.gz

Download URL persistent_crypto_dict-0.5.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0e9bf7e12b6803ced6f6b8d83c9d159f9cc91589125a2094446a90b4d6e227ed
BLAKE2b-256 checksum
How to use checksums
9d6c3af806b8586dbabe14339b5e6e03d84395dc4d807f552997d8ae87478e73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

Security for persistent-crypto-dict 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page