🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Data Management / Database Administration › Database Security & Role Management › Lesson 5
TEC-DATA86-05 · Lesson 5 · 10 clock hours · lab

Encryption at Rest: TDE Concepts, pgcrypto & Column Encryption

Objective. Learners apply column-level encryption to sensitive fields in PostgreSQL using the pgcrypto extension and describe how Oracle TDE and Azure SQL TDE protect data files at rest.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Encryption at Rest: TDE Concepts, pgcrypto & Column Encryption

Why Encrypt Data at Rest?

Data at rest means data stored on disk—database files, backups, log files, and temporary files. If an attacker steals a physical hard drive or gains raw file access, plaintext data is immediately readable unless encryption protects it. Encryption at rest ensures that even without the database engine, the data remains unreadable. This matters for compliance with frameworks such as HIPAA, PCI-DSS, and SOC 2, and it is tested directly on the Oracle DBA CA, Microsoft DP-300, and DAMA CDMP exams.

Three Approaches Compared

1. Application-Level (Column) Encryption — pgcrypto in PostgreSQL

The `pgcrypto` extension adds cryptographic functions directly inside PostgreSQL. Encryption and decryption happen at the SQL layer before data is written to or read from storage. The database engine itself stores only ciphertext in the column; even a DBA with OS-level access to the data files sees scrambled bytes.

The encryption boundary is at the SQL statement: only a caller who supplies the correct passphrase (or key) can decrypt. This means key management is the application's or DBA's responsibility. If the passphrase is lost, data is unrecoverable.

Core functions:

Because the output is `bytea`, the encrypted column is defined as `bytea`, not `text`.

2. Oracle Transparent Data Encryption (TDE)

Oracle TDE encrypts data files, redo logs, and undo segments at the storage layer. The word transparent means the database engine decrypts data automatically when an authorized session reads it; applications require no code changes. The encryption boundary is between the Oracle engine and the OS/storage layer.

Oracle TDE supports tablespace-level encryption (the entire tablespace is encrypted) and column-level encryption (individual columns). The master encryption key is stored in an Oracle Wallet or a Hardware Security Module (HSM). If someone steals the data files but not the wallet, they cannot read the data.

3. Azure SQL / SQL Server Transparent Data Encryption (TDE)

Azure SQL Database enables TDE by default on all new databases. It encrypts the entire database data file, log file, and backups using AES-256. The encryption boundary is between the SQL Server engine and the storage subsystem. Two key management modes are available:

Applications connect and query normally; decryption is invisible. This maps to DP-300 exam content on Azure SQL security.

Where the Encryption Boundary Lies

| Approach | Boundary | Who Holds the Key | Transparent to App? |

|---|---|---|---|

| pgcrypto (PostgreSQL) | SQL function call | Application / DBA | No — app must call decrypt function |

| Oracle TDE | Database engine ↔ OS | Oracle Wallet / HSM | Yes |

| Azure SQL TDE | Database engine ↔ Storage | Microsoft or Key Vault | Yes |

Installing pgcrypto and Encrypting a Column

The `pgcrypto` extension ships with the standard PostgreSQL distribution. A superuser installs it once per database:

```sql

CREATE EXTENSION IF NOT EXISTS pgcrypto;

```

An `employees` table with an encrypted SSN column:

```sql

CREATE TABLE employees (

emp_id SERIAL PRIMARY KEY,

name TEXT NOT NULL,

ssn_enc BYTEA

);

```

Inserting a row:

```sql

INSERT INTO employees (name, ssn_enc)

VALUES (

'Jane Smith',

pgp_sym_encrypt('123-45-6789', 'my_strong_passphrase')

);

```

Decrypting for authorized queries:

```sql

SELECT name,

pgp_sym_decrypt(ssn_enc, 'my_strong_passphrase') AS ssn

FROM employees;

```

A direct `SELECT ssn_enc FROM employees` returns binary ciphertext. Inspecting the underlying data file with OS tools (`strings`, `pg_filedump`) reveals no readable SSN.

Passphrase and Key Security

A passphrase hardcoded in application source code defeats the purpose of encryption. Best practices:

Safety and Operational Cautions

Key terms10

Encryption at RestThe protection of stored data by converting it to ciphertext so it is unreadable without the correct key, even if the physical storage medium is stolen or accessed outside the normal system.
pgcryptoA PostgreSQL extension that provides cryptographic functions including symmetric and asymmetric encryption, hashing, and random data generation directly within SQL queries.
pgp_sym_encrypt / pgp_sym_decryptpgcrypto functions that encrypt or decrypt a text value using OpenPGP symmetric-key encryption with a caller-supplied passphrase, returning or accepting a bytea value.
Transparent Data Encryption (TDE)A database feature, available in Oracle and SQL Server/Azure SQL, that automatically encrypts data files at the storage layer so applications and users experience no change in how they query data.
Database Encryption Key (DEK)The symmetric key used by SQL Server and Azure SQL TDE to encrypt the actual database pages; the DEK itself is protected by a master key stored in a certificate or Azure Key Vault.
Oracle WalletA secure file-based container used by Oracle Database to store the TDE master encryption key and other credentials; must be open for TDE-encrypted tablespaces or columns to be accessible.
Column-Level EncryptionAn encryption strategy in which only specific columns in a table are encrypted, allowing other columns to be queried normally while protecting the most sensitive fields such as SSNs or payment card numbers.
Encryption BoundaryThe point in a system architecture at which plaintext data is converted to ciphertext; identifying this boundary determines who can access plaintext and what threats are mitigated.
Bring Your Own Key (BYOK)A key management model in cloud services such as Azure SQL where the customer provides and controls the master encryption key through a service like Azure Key Vault rather than relying on provider-managed keys.
byteaA PostgreSQL data type for storing binary strings; the output of pgp_sym_encrypt is bytea because encrypted data is arbitrary binary content, not valid text.
In class: Lab setup: learners install the pgcrypto extension, create an employees table with an encrypted ssn column, and write INSERT and SELECT statements using pgp_sym_encrypt and pgp_sym_decrypt with a passphrase; they confirm that a raw table scan (pg_filedump or strings on the data file) does not reveal plaintext SSN values. · Concept mapping: learners complete a diagram worksheet mapping the pgcrypto approach (application-level) vs. Oracle TDE tablespace encryption vs. Azure SQL service-managed TDE, identifying where the encryption boundary lies in each case and who holds the key. · Written scenario response: given a breach scenario where a hard drive is stolen from a server, learners write a paragraph explaining which encrypted columns or TDE configurations would protect the data and why, referencing their diagram.
Materials: PostgreSQL pgcrypto documentation, Oracle TDE documentation excerpt (docs.oracle.com), Microsoft DP-300 study guide (encryption at rest section), Linux VMs, pgcrypto extension, sample schema SQL
Check: Learner runs instructor-provided SELECT against their table; pgp_sym_decrypt must return the original SSN for authorized query and raw file inspection must show ciphertext only. Pass = both conditions met plus correct written scenario response (instructor rubric: 3 of 3 key points addressed).

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

PostgreSQL CE — Security and Extensions
1. A learner runs `SELECT ssn_enc FROM employees;` and sees binary-looking output instead of a Social Security Number. What is the most accurate explanation?
PostgreSQL CE — Extensions and Configuration
2. Which SQL statement correctly installs the pgcrypto extension in a PostgreSQL database?
Oracle DBA CA — Security
3. A hard drive containing Oracle Database data files is stolen from a data center. The thief does not have access to the Oracle Wallet. Which statement is correct regarding data protection?
Microsoft DP-300 — Implement a Secure Environment
4. In the Azure SQL TDE model with service-managed keys, who controls the Database Encryption Key (DEK)?
PostgreSQL CE — Security and Extensions
5. A developer stores the pgcrypto passphrase as a plaintext string in the application source code committed to a public Git repository. What is the primary security risk?
DAMA CDMP — Data Security
6. What is the primary distinction between pgcrypto column encryption and Oracle TDE tablespace encryption in terms of the encryption boundary?
PostgreSQL CE — Backup and Security
7. A DBA wants logical backups created with `pg_dump` of a PostgreSQL database containing pgcrypto-encrypted columns to also be protected in transit and at rest. What additional step is required?
DAMA CDMP — Data Security
8. According to the DAMA CDMP body of knowledge, which data management domain most directly addresses policies for classifying sensitive data fields such as SSNs and determining whether they require encryption?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.