diff options
author | Yigit Sever | 2021-04-16 05:47:08 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-16 05:47:08 +0300 |
commit | b7cd484a869600e181dd06522befbfd091a7a488 (patch) | |
tree | a6176a72a7b8adc3b1ae9bed73adc8a7b1f3674f /scripts | |
parent | f46572b5befc3fc1af6e33d8e8b61f47e1c18058 (diff) | |
download | gradecoin-b7cd484a869600e181dd06522befbfd091a7a488.tar.gz gradecoin-b7cd484a869600e181dd06522befbfd091a7a488.tar.bz2 gradecoin-b7cd484a869600e181dd06522befbfd091a7a488.zip |
Almost passsing auth
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/encryptor.py | 57 |
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 @@ | |||
1 | import os | ||
2 | from cryptography.hazmat.primitives.ciphers.modes import CBC | ||
3 | from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes | ||
4 | from cryptography.hazmat.primitives import padding | ||
5 | import base64 | ||
6 | import binascii | ||
7 | |||
8 | def bin2hex(binStr): | ||
9 | return binascii.hexlify(binStr) | ||
10 | |||
11 | def hex2bin(hexStr): | ||
12 | return binascii.unhexlify(hexStr) | ||
13 | |||
14 | iv = hex2bin("6e657665726d696e647468656e66756b") | ||
15 | key = hex2bin("6e6565726d666e646e6565726d666e64") | ||
16 | |||
17 | mode = CBC(iv) | ||
18 | |||
19 | cipher = Cipher(algorithms.AES(key), mode) | ||
20 | |||
21 | encryptor = cipher.encryptor() | ||
22 | |||
23 | padder = padding.PKCS7(128).padder() | ||
24 | |||
25 | payload_string = """{"public_key":"-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzJN9ALFoUHE8SigFhtql | ||
26 | \\n+GPI6dIVHDCfAFXe6DU131yXoL14imBRBb5SevMou5WGiL7XBTdtlRaY8+dkNdFz\\nWEMhPoe++/GvV3u6Mq6UAJMjuiJj838NbJVl+83+NEP66htXpqidTIdr | ||
27 | 7syaRU1T\\n0PfgvVYdNkwiWkTVtwveRchGtUwp2iZePMSF1+vtKKDvzXgZuwrKBhwBFXz6ApSZ\\n+eGkWhK1pW6TRTSENlySwb/DEg5PckzOzApLTTQqi4uu+sHU | ||
28 | D+McAtOP9pNILwst\\nG87LxNEO0roFqUaDIhRolgkF8jol2BUZmKChdy84XX+L6jpqDvPsxuTUpIghr0Jq\\nvQIDAQAB\\n-----END PUBLIC KEY-----","st | ||
29 | udent_id":"e223795","passwd":"pmcTCKox99NFsqp"}""" | ||
30 | |||
31 | byte_guys = str.encode(payload_string) | ||
32 | padded_data = padder.update(byte_guys) | ||
33 | |||
34 | ct = encryptor.update(padded_data) + encryptor.finalize() | ||
35 | |||
36 | c = base64.b64encode(ct) | ||
37 | |||
38 | import Crypto | ||
39 | from Crypto.Cipher import PKCS1_OAEP | ||
40 | from Crypto.PublicKey import RSA | ||
41 | |||
42 | gradecoin_key = """-----BEGIN PUBLIC KEY----- | ||
43 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyGuqiCPGcguy+Y9TH7Bl | ||
44 | 7XlEsalyqb9bYlzpbV0dnqZ3lPkEPkuOhkN+GcuiV6iXtSwyh7nB+xTRXKJFRUBO | ||
45 | /jbN8jfcxVwBu0JxjF3v1YRBxbOHhz2A295mbKD9xHQCKxkfYBNkUXxj8gd+GaDv | ||
46 | QiSW5NdrX/lEkvqfGtdEX1m2+HdcG0+3YW24Xg0znhCwLr+sorLuJaDy9Xa0Uo+D | ||
47 | PWGC5s001U/BxkCIWJ+eJQCb7Bv+9vXb8BGRK/ecMb/fb6h5O+8fgB64RCHMgcc2 | ||
48 | v+Q/dPt8kHX1OJdMuYUrUJGACppMQY3W6e1HdlRIBcZKL2LMZ2CrIB/2D5LiJhPT | ||
49 | hQIDAQAB | ||
50 | -----END PUBLIC KEY-----""" | ||
51 | |||
52 | publickey = RSA.import_key(gradecoin_key) | ||
53 | |||
54 | asy_cipher = PKCS1_OAEP.new(publickey, hashAlgo=Crypto.Hash.SHA256) | ||
55 | ciphertext = asy_cipher.encrypt(key) | ||
56 | |||
57 | key = base64.b64encode(ciphertext) | ||