K
K
Kudalar2020-01-29 23:29:26
Python
Kudalar, 2020-01-29 23:29:26

What is the correct way to send an encrypted POST request in Python?

The response to the POST request is 'Seems you are providing invalid input data. Provide data in valid format.'
AES/ECB/PKCS5Padding encryption algorithm. I've been suffering for several days now, I've read and tried a lot. User_token is issued freely after registration. Instructions from the site:

Request URL : https://bondevalue.com/app/bondDetailsHistoryData
Request Method : POST
Request Content-Type : application/x-www-form-urlencoded
Request Parameter :
requestData
= "{\"data\":{\"userToken\ ":\"[userToken]\"},\"bondISINId\":\"[isinId]"\"" "\"fromDate\":\"[from
date]\" "}"
[Note: The requestData will be encrypted by a encryption algorithm]
Example:
Before Encryption Data : {
"data":{"userToken":"slabnt1l540udrh0"},"bondISINcode":"XS1401197253" "fromDate":""}ylwciqc9e2E4kwYCRRsAvUcQlQ7cn23QMO22i+9FH/3n4peo+9dm7XMnNSx3E45WZiNEUsepGQN HED2kzqKporz5bQTOzP8i/tD57OCE7kUr5EIeaqk8OKzmHu8KeQAM
Note: This particular API requires the bond 's ISIN Id and the from date to view the history data for
that particular ISIN ID.



My code:
import requests
import json
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64

client_token = b'1234123412341234'
requestData = b'{\"data\":{\"userToken\":\"[1234123412341234]\"},\"bondISINId\":\"[XS1401197253]\", \"fromDate\":\"[2016-12-07]\"}'
cipher1 = AES.new(client_token, AES.MODE_ECB)
requestEncrypted = base64.b64encode(cipher1.encrypt(pad(requestData, 16))).decode('utf-8')

url = 'https://bondevalue.com/app/bondDetailsHistoryData'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {'requestData': requestEncrypted}

answer = requests.post(url=url, data=requestEncrypted, headers=headers)
response = answer.json()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-01-30
@Survtur

Could it be the square brackets? Example: Before Encryption Data doesn't have them, but you have them in your code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question