Created
May 17, 2021 13:36
-
-
Save scalone/d29809da67aaf92750da61ee71ee45b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jwcrypto import jwk, jwe | |
import json | |
import time | |
def encrypt(payload): | |
payload = json.dumps(payload) | |
protected_header = { | |
"alg": "RSA-OAEP-256", | |
"enc": "A128GCM", | |
"kid": "<KID>", | |
"iat": int(round(time.time() * 1000)) | |
} | |
jwetoken = jwe.JWE(payload.encode('utf-8'), | |
recipient=loadPem('./server_cert.pem'), | |
protected=protected_header) | |
encryptedPayload = jwetoken.serialize(compact=True) | |
return {"encData": encryptedPayload} | |
def loadPem(filePath): | |
with open(filePath, "rb") as pemfile: | |
return jwk.JWK.from_pem(pemfile.read()) | |
request_timestamp = 12341234 | |
payload = { | |
'requestHeader': { | |
'requestTS': request_timestamp, | |
'requestMessageID': "SINGLE_BIN_LOOKUP-#{request_timestamp}", | |
}, | |
'requestData': { | |
'paymentAccountType': 'P', | |
'paymentAccount': '<PAN>' | |
} | |
} | |
print(encrypt(payload)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment