From 59c995eef43aa5588a047a71b8d3cd980f9b5d21 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 26 Jul 2024 23:19:10 +0700 Subject: [PATCH] Create CryptoModel.py --- coin/models/CryptoModel.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 coin/models/CryptoModel.py diff --git a/coin/models/CryptoModel.py b/coin/models/CryptoModel.py new file mode 100644 index 000000000..bdd2aceee --- /dev/null +++ b/coin/models/CryptoModel.py @@ -0,0 +1,21 @@ +import hashlib + +class CryptoModel: + def __init__(self): + pass + + def generate_key_pair(self) -> (str, str): + # Generate a new key pair + private_key = hashlib.sha256("private_key".encode()).hexdigest() + public_key = hashlib.sha256("public_key".encode()).hexdigest() + return private_key, public_key + + def encrypt(self, data: str, public_key: str) -> str: + # Encrypt data using a public key + encrypted_data = hashlib.sha256(f"{data}{public_key}".encode()).hexdigest() + return encrypted_data + + def decrypt(self, encrypted_data: str, private_key: str) -> str: + # Decrypt data using a private key + decrypted_data = hashlib.sha256(f"{encrypted_data}{private_key}".encode()).hexdigest() + return decrypted_data