verschlüsselung
This commit is contained in:
@@ -3,6 +3,7 @@ import toml
|
||||
from platformdirs import user_config_dir
|
||||
from pathlib import Path
|
||||
from PySide6.QtCore import QObject, Slot
|
||||
from .Vermasseln import Vermasseln
|
||||
|
||||
|
||||
class ConfigLoader(QObject):
|
||||
@@ -20,29 +21,12 @@ class ConfigLoader(QObject):
|
||||
|
||||
@Slot(dict)
|
||||
def setConfig(self, app_config):
|
||||
pyqcrm = '[pyqcrm]\n'
|
||||
db = '[database]\n'
|
||||
for k, v in app_config.items():
|
||||
if k == 'username':
|
||||
pyqcrm = pyqcrm + f"PYQCRM_ADMIN = \"{v}\"\n"
|
||||
elif k == 'password':
|
||||
pyqcrm = pyqcrm + f"PYQCRM_ADMIN_PASS = \"{v}\"\n"
|
||||
elif k == 'db-host':
|
||||
db = db + f"DB_HOST = \"{v}\"\n"
|
||||
elif k == 'db-name':
|
||||
db = db + f"DB_PORT = \"{v}\"\n"
|
||||
elif k == 'db-port':
|
||||
db = db + f"DB_NAME = \"{v}\"\n"
|
||||
elif k == 'db-username':
|
||||
db = db + f"DB_USER = \"{v}\"\n"
|
||||
elif k == 'db-password':
|
||||
db = db + f"DB_PASS = \"{v}\"\n"
|
||||
|
||||
appconf = pyqcrm + '\n' + db + '\n'
|
||||
|
||||
try:
|
||||
with open (self.config_dir + '/pyqcrm.toml', 'w') as f:
|
||||
f.write(appconf)
|
||||
config = Vermasseln().oscarVermasseln(toml.dumps(app_config))
|
||||
f.write(config)
|
||||
except FileNotFoundError:
|
||||
print("Konnte die Konfiguration nicht speichern.")
|
||||
|
||||
@@ -51,11 +35,14 @@ class ConfigLoader(QObject):
|
||||
|
||||
try:
|
||||
with open (self.config_dir + '/pyqcrm.toml', 'r') as f:
|
||||
self.__config = toml.load(f)
|
||||
config = f.read()
|
||||
self.__config = toml.loads(Vermasseln().entschluesseln(config))
|
||||
print(self.__config)
|
||||
except FileNotFoundError:
|
||||
print("Konnte die Konfiguration nicht laden.")
|
||||
|
||||
|
||||
|
||||
def getConfig(self):
|
||||
|
||||
return self.__config
|
||||
|
||||
41
lib/Vermasseln.py
Normal file
41
lib/Vermasseln.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
from Crypto import Random
|
||||
from Crypto.Cipher import AES
|
||||
from base64 import b64encode, b64decode
|
||||
import platform
|
||||
from Crypto.Hash import SHA256
|
||||
|
||||
|
||||
class Vermasseln:
|
||||
def oscarVermasseln(self, data):
|
||||
b_data = data.encode("utf-8")
|
||||
cipher = self.__vermasslungsKobold()
|
||||
|
||||
ciphertext, tag = cipher.encrypt_and_digest(b_data)
|
||||
decoded_data = [b64encode(x).decode("utf-8") for x in (ciphertext, tag)]
|
||||
storable_data = ".".join(decoded_data)
|
||||
|
||||
return storable_data
|
||||
|
||||
def entschluesseln(self, data):
|
||||
data_list = data.split(".")
|
||||
encoded_data = [b64decode(x) for x in data_list]
|
||||
cipher = self.__vermasslungsKobold()
|
||||
decrypted_data = cipher.decrypt_and_verify(encoded_data[0], encoded_data[1])
|
||||
decrypted_data = decrypted_data.decode("utf-8")
|
||||
return decrypted_data
|
||||
|
||||
def __vermasslungsKobold(self):
|
||||
key = platform.processor().encode("utf-8")
|
||||
key = key[0:31]
|
||||
hash_key = SHA256.new(key)
|
||||
hashed = hash_key.digest()
|
||||
nonce = platform.machine().encode("utf-8")
|
||||
cipher = AES.new(hashed, AES.MODE_SIV, nonce = nonce)
|
||||
return cipher
|
||||
|
||||
print(Vermasseln().oscarVermasseln("irgendeinenText"))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user