From edfab6ae2f97a7288ff456265050c01ff397ea8c Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 03:27:27 +0300 Subject: [WIP] Initial implementation of user auth There is a dance involved and everything Write down specs for RSA and AES, padding scheme, ugh. --- scripts/python_client.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 scripts/python_client.py (limited to 'scripts') diff --git a/scripts/python_client.py b/scripts/python_client.py new file mode 100644 index 0000000..fe96cc2 --- /dev/null +++ b/scripts/python_client.py @@ -0,0 +1,57 @@ +from Crypto.PublicKey import RSA +import json +from Crypto.Cipher import PKCS1_OAEP +from Crypto.Signature import PKCS1_v1_5 +from Crypto.Hash import SHA512, SHA384, SHA256, SHA, MD5 +from Crypto import Random +from base64 import b64encode, b64decode +hash = "SHA-256" + +# def newkeys(keysize): +# random_generator = Random.new().read +# key = RSA.generate(keysize, random_generator) +# private, public = key, key.publickey() +# return public, private + +# def importKey(externKey): +# return RSA.importKey(externKey) + +# def getpublickey(priv_key): +# return priv_key.publickey() + + +def encrypt(message, pub_key): + cipher = PKCS1_OAEP.new(pub_key) + return cipher.encrypt(message) + + +if __name__ == "__main__": + + myself = { + "student_id": "e2482057", + "public_key": """-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3agASpH/TplIAX0YBqmh +5q3Iq6+LcJtlUVWiI/v0T74XwYPZaJpAArHaiMUGXAWxmzfbvEo1wE9RzySYV/5k +QSpYDRekpOn0flIAQHORVbJ08s0udH6/c2AyAzqiwZbR1DRr7M90pSLvWvzHQT+c +kT6rXYcp9GlSAv3AXRw5ZYalbQf7ST/Mb4T8O1MRkAatzXg3T4x3XJ3uxHOletLL +SzsfY52kEn0uaFG6UI7UG50h8jcjqBxn+ETbn2YEZG5ecmPdYNakq2pqrdWXWMhE +AUd927qkxgg/nyyFqwxIbTxebxzpNX8IHMT8PgNdMxVMqnhBWxiw1nborY+pwGVL +MwIDAQAB +-----END PUBLIC KEY-----""" + } + with open("../secrets/gradecoin.pub", "r") as fs: + data = fs.read() + pubkeyobj = RSA.importKey(data) + + cipher = PKCS1_OAEP.new(pubkeyobj) + + ser = json.dumps(myself, separators=(',', ':')) + + a = cipher.encrypt(ser) + + print(f"{a}") + + + + + -- cgit v1.2.3-70-g09d2