You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
753 B
Python
31 lines
753 B
Python
1 year ago
|
#!/usr/bin/env python3
|
||
|
import requests
|
||
|
import base64
|
||
|
from Crypto.Cipher import AES
|
||
|
|
||
|
MODE = AES.MODE_CFB
|
||
|
BLOCK_SIZE = 16
|
||
|
SEGMENT_SIZE = 128
|
||
|
|
||
|
def _pad_string(value):
|
||
|
length = len(value)
|
||
|
pad_size = BLOCK_SIZE - (length % BLOCK_SIZE)
|
||
|
return value.ljust(length + pad_size, '\x00')
|
||
|
|
||
|
def encrypt(key, iv, plaintext):
|
||
|
aes = AES.new(key, MODE, iv, segment_size=SEGMENT_SIZE)
|
||
|
plaintext = _pad_string(plaintext)
|
||
|
encrypted_text = aes.encrypt(plaintext)
|
||
|
return encrypted_text
|
||
|
|
||
|
|
||
|
key = 'TfvY7I358yospfWKcoviZizOShpm5hyH'
|
||
|
iv = 'mb13KcoviZizvYhp'
|
||
|
original_message = 'hi'
|
||
|
|
||
|
encryptedpayload = base64.b64encode(encrypt(key, iv, original_message))
|
||
|
|
||
|
request = requests.post("http://localhost:8080/hello", encryptedpayload)
|
||
|
|
||
|
|
||
|
print(request.content)
|