blob: 2dac48777ba7df193d9d3baae377d3f56e7f21f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import os
from cryptography.hazmat.primitives.ciphers.modes import CBC
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import padding
import base64
import binascii
def bin2hex(binStr):
return binascii.hexlify(binStr)
def hex2bin(hexStr):
return binascii.unhexlify(hexStr)
iv = hex2bin("6e657665726d696e647468656e66756b")
key = hex2bin("6e6565726d666e646e6565726d666e64")
mode = CBC(iv)
cipher = Cipher(algorithms.AES(key), mode)
encryptor = cipher.encryptor()
payload = dict()
payload["public_key"] = """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoNsLhsQzL+5HiGuaI4mu
K0TqiLEOFPOl8kd9pWR8eop0b7/N2ggDRXATIkV+XwzeQp+k9lGT1h2B2bDhxn51
lBESb2rSqKKzTVf4SXoPxqvPwsi1bnmHcRG8tTr+ZWcJdblXabMUkKUJCrwKhvr8
UpOi0tndcc7buVq4EWCIBUeG4SCFHeBu1Ue9Zus7BpwjSxF4jHH4M8ssl/ioN8+m
qz9LcDQe3kvVRMlVbaXjYnWyP0VjwRbQuwIjMsDVaTQUIVtPZY9el7LiIxCqZ4mO
cnnwlIZyGLN52uqDZ1cz7aSO18YIGcbCpxuOuPhSzrnZNvHJZFIkacd477fK+PKB
7QIDAQAB
-----END PUBLIC KEY-----"""
payload["student_id"] = "e223795"
payload["passwd"] = "pmcTCKox99NFsqp"
import json
payload_string = json.dumps(payload)
byte_guys = str.encode(payload_string)
padder = padding.PKCS7(128).padder()
padded_data = padder.update(byte_guys)
padded_data += padder.finalize()
ct = encryptor.update(padded_data) + encryptor.finalize()
c = base64.b64encode(ct)
import Crypto
from Crypto.Cipher import PKCS1_OAEP
from Crypto.PublicKey import RSA
gradecoin_key = """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyGuqiCPGcguy+Y9TH7Bl
7XlEsalyqb9bYlzpbV0dnqZ3lPkEPkuOhkN+GcuiV6iXtSwyh7nB+xTRXKJFRUBO
/jbN8jfcxVwBu0JxjF3v1YRBxbOHhz2A295mbKD9xHQCKxkfYBNkUXxj8gd+GaDv
QiSW5NdrX/lEkvqfGtdEX1m2+HdcG0+3YW24Xg0znhCwLr+sorLuJaDy9Xa0Uo+D
PWGC5s001U/BxkCIWJ+eJQCb7Bv+9vXb8BGRK/ecMb/fb6h5O+8fgB64RCHMgcc2
v+Q/dPt8kHX1OJdMuYUrUJGACppMQY3W6e1HdlRIBcZKL2LMZ2CrIB/2D5LiJhPT
hQIDAQAB
-----END PUBLIC KEY-----"""
publickey = RSA.import_key(gradecoin_key)
asy_cipher = PKCS1_OAEP.new(publickey, hashAlgo=Crypto.Hash.SHA256)
ciphertext = asy_cipher.encrypt(key)
key = base64.b64encode(ciphertext)
|