Decrypting Data with Smart Data Proxies
This guide explains how to use the Qanapi Smart Data Proxy to decrypt previously encrypted data.Decryption Process Overview
When you decrypt data with the Smart Data Proxy:- Your application sends a JSON payload containing encrypted data to your project’s proxy endpoint
- You specify which fields to decrypt using the
X-Qanapi-Fieldsheader - Qanapi authenticates your request and decrypts the specified fields
- The decrypted data is returned in the same structure, with plaintext values replacing the encrypted values
Basic Decryption Request
Here’s a basic example of how to decrypt data using the Smart Data Proxy:Understanding the Headers
For decryption requests, you need to include these headers:| Header | Value | Description |
|---|---|---|
X-Qanapi-Authorization | your_api_key | Your API key for authentication |
X-Qanapi-Mode | decrypt | Specifies that you want to decrypt data |
X-Qanapi-Fields | title,body | Comma-separated list of field names to decrypt |
Content-Type | application/json | Specifies that the payload is JSON |
Optional Headers for Decryption
You can also include these optional headers:| Header | Example Value | Description |
|---|---|---|
X-Qanapi-Classification | cui | Verifies that the data has the specified classification |
X-Qanapi-Destination | https://example.com/api | Forwards the decrypted data to this URL |
Sample Response
When decrypting data, the response will contain the original JSON structure with the specified encrypted fields replaced by their plaintext values:Decrypting Nested JSON Objects
You can decrypt fields within nested JSON objects by using dot notation in theX-Qanapi-Fields header:
Access Control and Classification Verification
When decrypting data, Qanapi verifies:- Authentication: Your API key must be valid
- Authorization: Your API key must have permission to decrypt the data
- Classification: If you specify a classification in the request, it must match the classification assigned during encryption
Handling Partially Encrypted Data
Your payload may contain a mix of encrypted and plaintext fields. The Smart Data Proxy will only attempt to decrypt the fields specified in theX-Qanapi-Fields header:
Error Handling
Common errors when decrypting data include:| Error Code | Description | Solution |
|---|---|---|
| 401 | Unauthorized | Check your API key |
| 400 | Bad Request | Ensure your JSON is valid and fields are correctly specified |
| 403 | Forbidden | You don’t have permission to decrypt this data |
| 422 | Unprocessable Entity | The data format may be incorrect or corrupted |
| 429 | Too Many Requests | You’ve exceeded the rate limit, wait and try again |
Best Practices for Decryption
- Decrypt only when necessary - Only decrypt data when it needs to be used in plaintext
- Verify classifications - Use the classification verification to ensure data integrity
- Secure your environment - Ensure your application environment is secure when handling decrypted data
- Implement proper error handling - Handle decryption errors gracefully in your application
- Clear decrypted data - Remove decrypted sensitive data from memory when no longer needed