JWT (Encryption & Signing) Guide
To ensure secure API communication, Juspay uses the JOSE framework, primarily through JWS (JSON Web Signature) for digitally signing/verifying messages and JWE (JSON Web Encryption) for encrypting/decrypting them. This dual-layer security helps prevent fraud, protect sensitive transaction data, and verify the sender’s identity.
JWT Setup
JWTs use 2048-bit asymmetric key pairs—one public and one private key. Since JWT involves both signing and encryption, two separate key pairs are used:
Merchant’s Key Pair: Generated by the merchant. The public key is shared with Juspay. Juspay uses merchant’s public key to verify signed requests and to encrypt responses sent back to the merchant.
Juspay’s Key Pair: Generated by Juspay and the public key shared. Merchant should use Juspay’s public key to encrypt the requests and to verify the responses send back to the merchant.
Sample Codes
To run the sample codes please ensure dependencies and files are properly setup. Encryption and Decryption codes make use of KeyProvider class or File to read keys.
Only for demo purposes the keys have been hardcoded inside the code, it’s unsafe and unsecured. Please keep the keys safe either in file system, env variables or some HSM.
Dependencies
Some of the programming languages use external dependencies. Please inject these dependencies in your code accordingly:
These libraries do not belong to Juspay, hence merchants discretion is required.
Java: nimbus-jose-jwt
, bouncy-castle
PHP: web-token/jwt-framework
. Please note that some additional dependencies may be required to build this if you are using version 4 or upwards of this dependency, which are listed below:
C#: jose-jwt
Python: pycryptodome
Key Provider
JWT Encryption
Pseudo Code
Demo Encryption Code
JWT Decryption
Pseudo Code
Demo Decryption Code
Download
You can download the above codes using the following link.
Key Rotations
Key rotations for JWT Encryption (Both API Request and Webhooks) are typically straightforward, thanks to the JOSE™ framework that contains protected kid information inside JWE™ and JWS™ headers. Merchants and Juspay can now mutually agree on key pairs using kid, enabling seamless key rotations with minimal changes at Merchant’s end (and possibly without any downtime).
Summary
- Have questions?
- Need help? Contact support
- LLM? Read llms.txt

