summaryrefslogtreecommitdiffstats
path: root/scripts/python_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/python_client.py')
-rw-r--r--scripts/python_client.py57
1 files changed, 57 insertions, 0 deletions
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 @@
1from Crypto.PublicKey import RSA
2import json
3from Crypto.Cipher import PKCS1_OAEP
4from Crypto.Signature import PKCS1_v1_5
5from Crypto.Hash import SHA512, SHA384, SHA256, SHA, MD5
6from Crypto import Random
7from base64 import b64encode, b64decode
8hash = "SHA-256"
9
10# def newkeys(keysize):
11# random_generator = Random.new().read
12# key = RSA.generate(keysize, random_generator)
13# private, public = key, key.publickey()
14# return public, private
15
16# def importKey(externKey):
17# return RSA.importKey(externKey)
18
19# def getpublickey(priv_key):
20# return priv_key.publickey()
21
22
23def encrypt(message, pub_key):
24 cipher = PKCS1_OAEP.new(pub_key)
25 return cipher.encrypt(message)
26
27
28if __name__ == "__main__":
29
30 myself = {
31 "student_id": "e2482057",
32 "public_key": """-----BEGIN PUBLIC KEY-----
33MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3agASpH/TplIAX0YBqmh
345q3Iq6+LcJtlUVWiI/v0T74XwYPZaJpAArHaiMUGXAWxmzfbvEo1wE9RzySYV/5k
35QSpYDRekpOn0flIAQHORVbJ08s0udH6/c2AyAzqiwZbR1DRr7M90pSLvWvzHQT+c
36kT6rXYcp9GlSAv3AXRw5ZYalbQf7ST/Mb4T8O1MRkAatzXg3T4x3XJ3uxHOletLL
37SzsfY52kEn0uaFG6UI7UG50h8jcjqBxn+ETbn2YEZG5ecmPdYNakq2pqrdWXWMhE
38AUd927qkxgg/nyyFqwxIbTxebxzpNX8IHMT8PgNdMxVMqnhBWxiw1nborY+pwGVL
39MwIDAQAB
40-----END PUBLIC KEY-----"""
41 }
42 with open("../secrets/gradecoin.pub", "r") as fs:
43 data = fs.read()
44 pubkeyobj = RSA.importKey(data)
45
46 cipher = PKCS1_OAEP.new(pubkeyobj)
47
48 ser = json.dumps(myself, separators=(',', ':'))
49
50 a = cipher.encrypt(ser)
51
52 print(f"{a}")
53
54
55
56
57