JSON Web Encryption (JWE) & JSON Web Signature (JWS)
JSON Web Encryption (JWE) represents encrypted content based on the JSON data structure. The cryptographic algorithms and identifiers for use with this specification are described in the JSON web algorithms (JWA) and IANA registries. The Related Digital Signatures and Message Authentication Code (MAC) capabilities are described separately in the JSON Web Signature (JWS) specification. To maximize security, JWE is being implemented for asymmetric encryption of sent requests.
The steps below are followed:
- Encrypt the request body, using a public key.
- Algorithm: RSA_OAEP
- Encryption method: A256CBC_HS512
- Public key (RSA .pem), this key is generated by NovoPayment and shared with the customer (NovoPayment is the owner of the private key)
- Sign the request body (encrypted text) by using a private key.
- Algorithm: RS512
- Private key (RSA .pem), this key is generated by the client. The client must generate a public key which must be shared with NovoPayment for signature verification on the request.
Note [important]: The JWE & JWS are enabled within the QA and Production environments. In sandbox environment, the client can consume the APIs without performing the JWE & JWS steps.
JWE keys generation and example of its use
This section describes the different steps to generate the JSON Web Encryption (JWE) keys. By using the “Open SSL” tool, please do the steps below.
Private Key generation
Command
{
$ openssl genpkey -algorithm RSA -out jwe_private_key.pem -pkeyopt rsa_keygen_bits:2048
}
Result
Public Key generation
Command
{
$ openssl rsa -pubout -in jwe_private_key.pem -out jwe_public_key.pem
}
Result
Usage
Below, the steps to perform in order to generate a JSON Web Encryption message.
jwe_public_key.pem content:
{
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA/L8BImxMGutiFyB2oY1l
29rQmGQrPxRl64h0ouzIHbj7Zm/r7flqeZG9dY19i1wWeeAG5wl15T3wvUPlV/xr
wv3MdEr3bmSQHipeXnm7UTB+LkSoIYmnqR9GEzQVJs42dmy4hYp1fLLBRh0blJnY
zfetkDWXiPhUuSv4kU+4/A7fMSFWDQpXC+Xae5i0Kd7TDwm2SVf31F6cyMTCY6Gk
SVmiBEZJEElKf2cPPVYlcRVsq+AtaC/dPU3wRVDoJtuwqG4jhSpi5yI7IajfsmiO
HKptQCsCIXYT5rsALDUgaeegVBCaidYNie5Ncl2Aie/5d69y5weliZzeFYmI8MIQ
5QIDAQAB
-----END PUBLIC KEY-----
}
**Payload example (without encryption):**
```js
{
"programId": "TDDOV",
"type": "named",
"expiration": "1825",
"line1": "TEST IOOO",
"line2": "debit",
"cardHolder": {
"accountNumber": "1601064713272000306529025205",
"documentType": "CC",
"documentNumber": "1999230927",
"firstName": "TAE NOM DCBZA",
"lastName": "TAE APE DCBZA",
"maternalSurname": null,
"birthDate": "1989-02-10",
"city": "Alban Cundinamarca",
"state": "Cundinamarca",
"country": "Colombia",
"nationality": "Colombiano",
"gender": "M",
"maritalStatus": "S",
"email": "tae_qbtjj@mailinator.com",
"address": "56 67 12 casa",
"codeAddress": "11002",
"birthPlace": "Colombia",
"phone": "573995935597",
"branchId": "1"
}
}
JWE representation of the payload:
eyJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwiYWxnIjoiUlNBLU9BRVAtMjU2In0.yFjF3DbNPfQuZtXbVaPgFk
3AcltIC_9a39E2ppY5avbqJdrYwZwPZphoD2N5mGCeipwfu3-
KoKAGadZS8DDB8WCWVfR_Wf2Hc7IJJsNXnMs5gZRzfFBiBpYyX-MdQ0YREYMyac1oD0as70hvc32aOtmChfrQSdMBxQkWDSJNF7TGZ_ml74eJjB14Ef7QCrxyBMevWJu
I2GtlKE9X2dWHkE4VFvnS4GniQsJkqhpe_OYFi8Eo5UHxHY2vfH6tbKVxzGnMVJtZBtd8SVAVIlSSkcSqi
_ggeE3AI9LMoTtJaiuzVUepsxAKC82bTxg1hTcy1b15KwiSg8DXHb4bzMJFOA.piFFKMwWKztbWnnC
GRb7hA.YU_o8TsYilMm697Y4mTDt480fJ4Rvq_JBL4MwuKIjPrrkIah8BJIId_Lclf2LqTT873EDkXSFPP01l
33Yt3vwIGsymXB0qd9RehpfUI4N6F8kyPgZ0_yQnnC33DSw5JVwDsCzWFISk4CjHk4TwOV8BoxYWF0
siuCV7_OeFA9Y1ByW8YRFpkjWSXd9CpGYwhU5sBrb-7iMqDx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GWtcih7qytSSzo7j5qElJAdMpPKI1XaWPieoIJEQHPnAb-fMNXyCFuo-SKwqYJKelkQGbL3Gu69ZHRtLCM2M3gmk-KWWAPn17A1JxgjPv-JT1LMqNigqDgXQTSvcgA_S-lwvZw1gTFv6hdOkeQPwXVDj-dxyVQW6t9c2YbwiSN8zu4F3B8KRdQgfexNrR9JrKRlJTD5VJkiFSftpaj0n00MbHN1YuejpUvsLZD8zZ6
H31ai-SFTGAhHF_5sVu8_tDAM9gJI3yBjYKIPFJT1SfQdqVfA9IhjbCJaZboF07s42vq8Q0H_YwEe2iF_NcnQHW
6yOwBfPh7OMhOocXzY1yNnAbnD1H9KqFjolvg4o80Ws_U6c38vC7kIYAUvdvv-wKayOyFISRa1nzOick5W1lG29FHCwtUSA.rzRGKI7CdSuw6cfjV4_TlTpWRpCZqjMmeI6--PO-Yh4"
}
JWS keys generation and example of its use
This section describes the different steps to generate the JSON Web Signature (JWS) keys.
By using the “Open SSL” tool, please do the steps below.
Private Key generation
Command
openssl genpkey -algorithm RSA -out jws_private_key.pem -pkeyopt rsa_keygen_bits:2048
Result
Public key generation
Command
$ openssl rsa -pubout -in jws_private_key.pem -out jws_public_key.pem
Result
Usage
Below, the steps to perform in order to generate a JSON Web Signature.
jws_private_key.pem content:
{
-----BEGIN PUBLIC KEY-----
MIIEpAIBAAKCAQEAzCB/DNHYN7Bse6QpuVoOnri6N/QX10znFo3HyW5tzClHsZTF
vvkJ+NM7YCBsmYNtahrm9EiA2HEPFY3bPfhxv6r8ywLPF+h7lnYA2UQIIy8L8kFm
VgpM/DTL0TEyQpkjzEp+eXG54nkRZP4qoDSaEeITt/0ib50FPRR8hZ9e00KPjfbf
TRDaxDIbFF2/ZkUjqi6+cX2g5dzPYuf/qemtv9+YyZEluOiwHjbbqRGmKe46xsGi
tdZ3Bmtm1VRpzjkJJRiV9As4OaS9wxAx3dNHzrlg4cXPJ8b2XfkbxbqDIYK7QMd6
Ig0uK5eG6mxLr8MiKuaZJhfzI3/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PfCZfaJ-x2fR9X_6sWNIrt-bUpOpbNxrCKJlkzdVS-DnfNzsDNZU87Hooa5Zg
JWS token usage: Once the JWS is generated, please include it in the request by defining the “X-Token” HTTP Header as described in the format below
X-Token: JWS + <JWS token>