Skip to content

Python library for encrypting and decrypting `sindresorhus/conf` files.

License

Notifications You must be signed in to change notification settings

DimmaDont/py-crypt-sindresorhus-conf

Repository files navigation

py-crypt-sindresorhus-conf

This Python library encrypts/decrypts sindresorhus/conf and sindresorhus/electron-store files.

Installation

# cryptography
pip install "crypt_sindresorhus_conf[cryptography] @ git+https://github.com/DimmaDont/py-crypt-sindresorhus-conf"

# PyCryptodome
pip install "crypt_sindresorhus_conf[pycryptodome] @ git+https://github.com/DimmaDont/py-crypt-sindresorhus-conf"

Usage example

Encryption

import json
import os

from crypt_sindresorhus_conf import CryptSindresorhusConf

key = b"hello there"
iv = os.urandom(16)
conf_crypt = CryptSindresorhusConf(key, iv)
encrypted = conf_crypt.encrypt(json.dumps({"foo": "bar"}))

Decryption

import json

from crypt_sindresorhus_conf import CryptSindresorhusConf

with open("file.json", "rb") as f:
    encrypted = f.read()

key = b"hello there"
iv = encrypted[:16]
conf_crypt = CryptSindresorhusConf(key, iv)
plaintext = conf_crypt.decrypt(encrypted)
data = json.loads(plaintext)