Update files

This commit is contained in:
2024-07-13 22:11:42 +02:00
parent 30fd109c86
commit cc2aca0f4d
14 changed files with 813 additions and 314 deletions

View File

@@ -1,20 +1,45 @@
"""
Module for encrypting configuration files using Fernet symmetric encryption.
"""
from cryptography.fernet import Fernet
class ConfigEncryptor:
"""
Class to handle encryption of configuration data.
"""
def __init__(self):
"""
Initialize the ConfigEncryptor with a generated encryption key.
"""
self.key = Fernet.generate_key()
def encrypt_config(self, data):
"""
Encrypt the configuration data and save it to 'config.enc'.
Args:
data (str): The configuration data to be encrypted.
"""
fernet = Fernet(self.key)
encrypted = fernet.encrypt(data.encode())
with open("config.enc", "wb") as encrypted_file:
encrypted_file.write(encrypted)
def get_key(self):
"""
Get the generated encryption key.
Returns:
str: The generated encryption key as a string.
"""
return self.key.decode()
if __name__ == "__main__":
config_data = """
CONFIG_DATA = """
{
"url": "https://yourstore.com",
"consumer_key": "ck_yourconsumerkey",
@@ -25,4 +50,4 @@ if __name__ == "__main__":
"""
encryptor = ConfigEncryptor()
print(f"Encryption key: {encryptor.get_key()}")
encryptor.encrypt_config(config_data)
encryptor.encrypt_config(CONFIG_DATA)