Encrypting Data with Smart Data Proxies
This guide demonstrates how to use the Qanapi Smart Data Proxy to encrypt sensitive data within JSON payloads.Encryption Process Overview
When you encrypt data with the Smart Data Proxy:- Your application sends a JSON payload to your project’s proxy endpoint
- You specify which fields to encrypt using the
X-Qanapi-Fieldsheader - Qanapi encrypts only those specified fields, leaving the rest untouched
- The encrypted data is returned in the same structure, with encrypted values replacing the original sensitive data
Basic Encryption Request
Here’s a basic example of how to encrypt data using the Smart Data Proxy:Understanding the Headers
For encryption requests, you need to include these headers:| Header | Value | Description |
|---|---|---|
X-Qanapi-Authorization | your_api_key | Your API key for authentication |
X-Qanapi-Mode | encrypt | Specifies that you want to encrypt data |
X-Qanapi-Fields | title,body | Comma-separated list of field names to encrypt |
Content-Type | application/json | Specifies that the payload is JSON |
Optional Headers for Encryption
You can also include these optional headers:| Header | Example Value | Description |
|---|---|---|
X-Qanapi-Classification | cui | Assigns a classification tag to the encrypted data |
X-Qanapi-Destination | https://example.com/api | Forwards the encrypted data to this URL |
Sample Response
When encrypting data, the response will contain the original JSON structure with the specified fields replaced by encrypted values:Encrypting Nested JSON Objects
You can encrypt fields within nested JSON objects by using dot notation in theX-Qanapi-Fields header:
Encrypting Arrays
To encrypt items in an array, specify the field name in theX-Qanapi-Fields header. All items in the array will be encrypted:
Using Data Classifications
Adding a classification to your encrypted data helps with access control and compliance:Error Handling
Common errors when encrypting 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 |
| 422 | Unprocessable Entity | Check that the fields you specified exist in your payload |
| 429 | Too Many Requests | You’ve exceeded the rate limit, wait and try again |
Best Practices for Encryption
- Only encrypt sensitive fields - Don’t encrypt everything, focus on sensitive data
- Use meaningful classifications - Apply appropriate classification tags for better access control
- Store encrypted data securely - Even though the data is encrypted, follow good security practices
- Document encrypted fields - Keep track of which fields are encrypted in your application
- Handle errors gracefully - Implement proper error handling in your application