Existing Application

πŸ“Œ Overview

This document provides a generalized implementation plan for integrating a Database Encryption Proxy into an existing application stack, with the goal of securing PII (Personally Identifiable Information) at rest without modifying the application code.


πŸ” Step 1: Identify PII Data to Protect

Start by identifying sensitive fields across tables in your existing database.

Table Name

Column Name

Type

Notes

users

email

Text

Login and contact info

users

username

Text

Unique identifier

users

phone_number

Text

Optional contact field

profiles

first_name

Text

User’s real name

profiles

last_name

Text

User’s real name

attributes

value

Text

Dynamic user attributes

βœ… Tip: Focus on data that is subject to privacy regulations such as GDPR, HIPAA, or local data protection laws.


βš™οΈ Step 2: Define Encryption Rules in config.yaml

Specify which columns should be encrypted and/or hashed using the proxy configuration file:

rules:
  sql:
    your_database:
      compatibility_mode: true
      scheme: public
      write:
        users:
          email:
            hash: true
          username:
            hash: true
          phone_number:
            hash: true
        profiles:
          first_name:
            hash: true
          last_name:
            hash: true
        attributes:
          value:
            hash: true

πŸ—οΈ Step 3: Install the Encryption Proxy

You can run the proxy using Docker:

Ensure it can connect to your actual database update your upstream configuration in config.yaml:


πŸ“₯ Step 4: Add New Columns to Support Encryption

The proxy requires additional columns to store encrypted and hashed versions:

  • <field>_ciphertext

  • <field>_digest

Use your migration tool (e.g., Flyway, Liquibase, or direct SQL):

If column is json

Repeat for all encrypted fields.


πŸ” Step 5: Run Migration to Encrypt Existing Data

Once configuration and schema are ready, run the migration tool:


πŸ”„ Step 6: Switch Application to Use Encryption Proxy

Update your application's database connection string to point to the proxy instead of the database:

Restart the application if needed.


βœ… Step 7: Validate Application Behavior

  • Test authentication/login

  • Check search functionality (note: partial search is not supported on encrypted fields)

  • Insert new records and verify encryption


πŸ” Security Notes

  • Use AES-GCM encryption (default)

  • Hashing enables exact-match search

  • Avoid enabling log_original_query in production


πŸ“Š Success Criteria

Criteria

Status

Application works without code changes

βœ…

PII fields are encrypted in the database

βœ…

Exact match search works as expected

βœ…

Data insert/update encrypted automatically

βœ…

Original data no longer visible in plaintext

βœ…


πŸ“Œ Next Steps

  • Perform security audit

  • Monitor performance impact

  • Rotate encryption keys periodically

  • Enable logging for auditing (if required by compliance)

This general documentation can be adapted to any application and schema. For assistance in adapting to your specific setup, feel free to reach out or fork the demo repo.

Last updated