Folks,
I am doing an API integration for fetching some data from my Vendor database. But they have this Python
script for doing an integration. I just wanted to have a head's up from you guys to help me out with how I can do the same with PHP
import M2Crypto
import hashlib
payload_template = """<payload><apiVersion>2.0</apiVersion><vendorId>jinna</vendorId><txnId>UTFTVAIAD</txnId><emailId>{encrypted_email_id}</emailId><destination>fetchData</destination><myAmount>100000</myAmount><Duration>24</Duration><Type>Home</Type><returnUrl>https://mydomainname.com</returnUrl></payload>"""
email_id = "jinna@mywebsite.com"
Read public key. This particular piece of code is to read the public key that these guys have shared with me.
public_key = M2Crypto.RSA.load_pub_key('/home/jinna/work/insights-client-keys/clients/mywebsite/public_key')
Encrypt email_id using Public Key and encode in Hex (Base16)
encrypted_email_id = public_key.public_encrypt(email_id, M2Crypto.RSA.pkcs1_padding).encode("hex")
Create payload.
payload = payload_template.format(encrypted_email_id = encrypted_email_id)
Generate SHA1 of payload and encode in Hex (Base16)
digest = hashlib.sha1(payload).hexdigest()
Read private key.
private_key = M2Crypto.RSA.load_key('/home/jinna/work/insights-client-keys/clients/mywebsite/private_key')
Encrypt digest using private key and encode in Hex (Base16)
signature = private_key.private_encrypt(digest, M2Crypto.RSA.pkcs1_padding).encode("hex")
Print payload and signature.
print payload, signature
Will appreciate your support.