Overview
The Modulus Labs QR API uses JWE (JSON Web Encryption) tokens to encrypt request and response payloads. This ensures that sensitive payment data is protected and maintains integrity throughout the entire transaction lifecycle.What is JWE? JSON Web Encryption is a standard for encrypting data in a compact, URL-safe format. It ensures that the payload cannot be read or modified during transit.
Why JWE Encryption?
Data Protection
Sensitive payment information is encrypted end-to-end
Integrity Verification
Any tampering with the token will cause verification to fail
Compliance
Meets security standards for financial transactions
Standardized
Uses industry-standard encryption algorithms
Encryption Specifications
The QR API requires specific encryption algorithms for JWE tokens:| Parameter | Value | Description |
|---|---|---|
| Content Encryption | A256CBC-HS512 | AES-256-CBC with HMAC SHA-512 |
| Key Wrap Algorithm | A256KW | AES-256 Key Wrap |
| Content Type | application/json | JSON payload format |
Your Encryption Key
Along with your Secret Key, Modulus Labs will provide you with an Encryption Key for JWE operations:Recommended Libraries
Use these well-tested libraries for creating and decrypting JWE tokens:- Node.js
- .NET
- PHP
Creating Request Payloads
Here’s how to encrypt your request data into a JWE token:Step 1: Prepare Your Data
First, construct the JSON payload with your transaction details:Step 2: Encrypt into JWE Token
Step 3: Wrap in Request Payload
Send the JWE token in your API request:Decrypting Response Payloads
The API returns JWE tokens in successful responses. Here’s how to decrypt them:Example Response
Decrypt the Token
Response Types
The API returns different response formats based on the request status:- Success
- Declined
Common Issues & Solutions
Invalid JWE Token Error
Invalid JWE Token Error
Cause: Mismatch in encryption algorithms or incorrect keySolution:
- Verify you’re using
A256KWfor key wrap - Verify you’re using
A256CBC-HS512for content encryption - Check that your encryption key is correct
- Ensure the key is Base64-decoded to raw bytes
Decryption Fails
Decryption Fails
Cause: Token has been modified or key mismatchSolution:
- Ensure the token hasn’t been modified during transit
- Verify you’re using the same encryption key for encryption and decryption
- Check that the token is complete (not truncated)
Library Compatibility Issues
Library Compatibility Issues
Cause: Not all JWT libraries support JWESolution:
- Use the recommended libraries listed above
- Ensure your library supports both
A256KWandA256CBC-HS512 - Update to the latest version of your chosen library
Base64 Encoding Issues
Base64 Encoding Issues
Cause: Incorrect encoding of binary dataSolution:
- Use URL-safe Base64 encoding (no padding)
- Ensure consistent encoding between encryption and decryption
- Use library-provided encoding functions
Security Best Practices
Key Storage
Store encryption keys in secure vaults or environment variables, never in code
Key Rotation
Implement a key rotation strategy for enhanced security
Validate Tokens
Always validate token structure and algorithms before decryption
Monitor Failures
Log and monitor decryption failures for potential security issues
Complete Example
Here’s a complete end-to-end example:Next Steps
Quickstart Guide
Follow a complete example with encryption
Create QR Endpoint
See the full API reference
Error Handling
Learn how to handle encrypted error responses
Testing
Test encryption in the sandbox environment