summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/encryptor.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/encryptor.py b/scripts/encryptor.py
new file mode 100644
index 0000000..008ac51
--- /dev/null
+++ b/scripts/encryptor.py
@@ -0,0 +1,57 @@
1import os
2from cryptography.hazmat.primitives.ciphers.modes import CBC
3from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
4from cryptography.hazmat.primitives import padding
5import base64
6import binascii
7
8def bin2hex(binStr):
9 return binascii.hexlify(binStr)
10
11def hex2bin(hexStr):
12 return binascii.unhexlify(hexStr)
13
14iv = hex2bin("6e657665726d696e647468656e66756b")
15key = hex2bin("6e6565726d666e646e6565726d666e64")
16
17mode = CBC(iv)
18
19cipher = Cipher(algorithms.AES(key), mode)
20
21encryptor = cipher.encryptor()
22
23padder = padding.PKCS7(128).padder()
24
25payload_string = """{"public_key":"-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzJN9ALFoUHE8SigFhtql
26\\n+GPI6dIVHDCfAFXe6DU131yXoL14imBRBb5SevMou5WGiL7XBTdtlRaY8+dkNdFz\\nWEMhPoe++/GvV3u6Mq6UAJMjuiJj838NbJVl+83+NEP66htXpqidTIdr
277syaRU1T\\n0PfgvVYdNkwiWkTVtwveRchGtUwp2iZePMSF1+vtKKDvzXgZuwrKBhwBFXz6ApSZ\\n+eGkWhK1pW6TRTSENlySwb/DEg5PckzOzApLTTQqi4uu+sHU
28D+McAtOP9pNILwst\\nG87LxNEO0roFqUaDIhRolgkF8jol2BUZmKChdy84XX+L6jpqDvPsxuTUpIghr0Jq\\nvQIDAQAB\\n-----END PUBLIC KEY-----","st
29udent_id":"e223795","passwd":"pmcTCKox99NFsqp"}"""
30
31byte_guys = str.encode(payload_string)
32padded_data = padder.update(byte_guys)
33
34ct = encryptor.update(padded_data) + encryptor.finalize()
35
36c = base64.b64encode(ct)
37
38import Crypto
39from Crypto.Cipher import PKCS1_OAEP
40from Crypto.PublicKey import RSA
41
42gradecoin_key = """-----BEGIN PUBLIC KEY-----
43MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyGuqiCPGcguy+Y9TH7Bl
447XlEsalyqb9bYlzpbV0dnqZ3lPkEPkuOhkN+GcuiV6iXtSwyh7nB+xTRXKJFRUBO
45/jbN8jfcxVwBu0JxjF3v1YRBxbOHhz2A295mbKD9xHQCKxkfYBNkUXxj8gd+GaDv
46QiSW5NdrX/lEkvqfGtdEX1m2+HdcG0+3YW24Xg0znhCwLr+sorLuJaDy9Xa0Uo+D
47PWGC5s001U/BxkCIWJ+eJQCb7Bv+9vXb8BGRK/ecMb/fb6h5O+8fgB64RCHMgcc2
48v+Q/dPt8kHX1OJdMuYUrUJGACppMQY3W6e1HdlRIBcZKL2LMZ2CrIB/2D5LiJhPT
49hQIDAQAB
50-----END PUBLIC KEY-----"""
51
52publickey = RSA.import_key(gradecoin_key)
53
54asy_cipher = PKCS1_OAEP.new(publickey, hashAlgo=Crypto.Hash.SHA256)
55ciphertext = asy_cipher.encrypt(key)
56
57key = base64.b64encode(ciphertext)