aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/encryptor.py
diff options
context:
space:
mode:
authorYigit Sever2021-04-16 05:47:08 +0300
committerYigit Sever2021-04-16 05:47:08 +0300
commitb7cd484a869600e181dd06522befbfd091a7a488 (patch)
treea6176a72a7b8adc3b1ae9bed73adc8a7b1f3674f /scripts/encryptor.py
parentf46572b5befc3fc1af6e33d8e8b61f47e1c18058 (diff)
downloadgradecoin-b7cd484a869600e181dd06522befbfd091a7a488.tar.gz
gradecoin-b7cd484a869600e181dd06522befbfd091a7a488.tar.bz2
gradecoin-b7cd484a869600e181dd06522befbfd091a7a488.zip
Almost passsing auth
Diffstat (limited to 'scripts/encryptor.py')
-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)