{"id":15395466,"url":"https://github.com/stef/persistent-crypto-dictionary","last_synced_at":"2025-10-14T19:32:14.476Z","repository":{"id":2289466,"uuid":"3247284","full_name":"stef/Persistent-Crypto-Dictionary","owner":"stef","description":"An encrypted persistent dictionary","archived":false,"fork":false,"pushed_at":"2021-07-20T18:24:12.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T23:17:19.418Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"An encrypted persistent dictionary","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"gaganjyot/Online-FElt","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stef.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-01-23T14:35:41.000Z","updated_at":"2023-10-27T18:11:41.000Z","dependencies_parsed_at":"2022-07-21T11:04:57.535Z","dependency_job_id":null,"html_url":"https://github.com/stef/Persistent-Crypto-Dictionary","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stef%2FPersistent-Crypto-Dictionary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stef%2FPersistent-Crypto-Dictionary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stef%2FPersistent-Crypto-Dictionary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stef%2FPersistent-Crypto-Dictionary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stef","download_url":"https://codeload.github.com/stef/Persistent-Crypto-Dictionary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245924494,"owners_count":20694728,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T15:28:26.996Z","updated_at":"2025-10-14T19:32:09.446Z","avatar_url":"https://github.com/stef.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Persistent Crypto Dictionary\n****************************\n\nThis class implements a persistent dictionary using sqlite3 and\nencrypts the keys and the values of the dictionary in a way, that\nmakes it very hard to bruteforce either the key or the values in the\ndb.\n\nexample usage::\n   \u003e\u003e\u003e from pcd import PersistentCryptoDict\n   \u003e\u003e\u003e d=PersistentCryptoDict()\n   \u003e\u003e\u003e print d\n   \u003cpcd.PersistentCryptoDict instance at 0x8dcb54c\u003e\n   \u003e\u003e\u003e print d['my key']\n   None\n   \u003e\u003e\u003e d['my key']='secret value'\n   \u003e\u003e\u003e print d['my key']\n   secret value\n   \u003e\u003e\u003e d['my key']='top secret value'\n   \u003e\u003e\u003e print d['my key']\n   top secret value\n\nCrypto\n======\n\nThe key and the value in the dict is transformed according to the\nfollowing algorithm (credit: dnet):\n\nSetting values\n++++++++++++++\n1. we calculate they keyhash - a hmac-sha512(salt,key)\n2. we split the key in half, the first half as a hexdigest (ascii),\n   the second we keep as a binary\n3. we use the second binary half from step 2 of the keyhash to encrypt\n   the value\n4. we use the ascii keyhash from step 2 as a key to the database, and\n   the value is the encrypted result from step 3.\n\nGetting values\n++++++++++++++\n1. we calculate they keyhash - a hmac-sha512(salt,key)\n2. we split the key in half, the first half as a hexdigest (ascii),\n   the second we keep as a binary\n3. we query the database using the ascii keyhash from step 2 as a key\n4. we use the second binary half from step 2 of the keyhash to decrypt\n   the value\n\nThe database contains only the following pairs of data:\n\n  (hmac-sha512(key, salt).hexdigest()[:64],                # key\n  aes256-ofb(hmac-sha512(key, salt).digest()[32:], value)) # value\n\nwe diligently obey Schneier's law:\nhttps://www.schneier.com/blog/archives/2011/04/schneiers_law.html, and\nthus we would consider the task to retrieve any meaningful data\nwithout huge rainbow tables from such a database a futile task. :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstef%2Fpersistent-crypto-dictionary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstef%2Fpersistent-crypto-dictionary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstef%2Fpersistent-crypto-dictionary/lists"}