Skip to content

Instantly share code, notes, and snippets.

@scalone
Created May 17, 2021 13:36
Show Gist options
  • Save scalone/d29809da67aaf92750da61ee71ee45b0 to your computer and use it in GitHub Desktop.
Save scalone/d29809da67aaf92750da61ee71ee45b0 to your computer and use it in GitHub Desktop.
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