DB2 encryption and cryptography

DB2 encryption is not one switch: a complete design protects data at rest, data moving over the network, credentials, and the keys that protect all three. This tutorial separates native SQL encryption functions from z/OS data-set encryption, TLS for DDF, RACF authorization, and operational key management.

Encryption and cryptography
Progress0 of 0 lessons

Start with a threat model

Encryption solves a specific exposure, not every security problem. A lost backup volume, a network packet capture, a curious privileged user, and a compromised application account are different threats. Begin by listing which sensitive columns need application-level secrecy, which Db2 data sets require platform protection, and which clients need encrypted DDF connections. Then decide who can decrypt, where keys live, and how access is audited.

Use layers deliberately. RACF and Db2 privileges decide whether an identity may run SQL. TLS protects the connection while requests travel. z/OS encryption protects eligible data sets at rest. Column-value encryption protects a value even when a user can read the table but is not entrusted with the plaintext key. A layer is not a substitute for the others.

  • Data in transit: TLS and AT-TLS for DDF, REST, and administrative paths.
  • Data at rest: encrypted Db2 and system data sets under approved z/OS facilities.
  • Data in use: least-privilege access, column masks, row permissions, and carefully managed cryptographic keys.

Native encryption functions and passwords

Db2 provides SQL encryption and decryption functions such as ENCRYPT_TDES and DECRYPT_CHAR, DECRYPT_BINARY, DECRYPT_BIT, and DECRYPT_DB on relevant releases. These password-based functions produce binary ciphertext and require the same password to decrypt the value. They are useful for legacy-compatible, application-controlled encrypted values, but they are not a replacement for enterprise key lifecycle tooling.

SET ENCRYPTION PASSWORD sets a session special-register value used when the function call does not supply a password. The password is case-sensitive and documented as 6 through 127 bytes. Do not put it in a string literal in source, SPUFI members, traces, or job output. Bind it through a host variable or parameter marker and keep the secret in an approved vault or RACF-protected mechanism.

sql
1
2
3
4
5
6
7
8
9
10
-- Application pattern: bind the value through a parameter marker +PREPARE SETPWD FROM 'SET ENCRYPTION PASSWORD = ?'; +EXECUTE SETPWD USING :encryption_password; + +INSERT INTO HR.EMPLOYEE_SECRET (EMPID, TAX_ID_ENCRYPTED) +VALUES (?, ENCRYPT_TDES(?)); + +SELECT DECRYPT_CHAR(TAX_ID_ENCRYPTED) + FROM HR.EMPLOYEE_SECRET + WHERE EMPID = ?;

Encryption hints and password protection

Some encryption interfaces permit a hint associated with the encrypted value. A hint is for a human or recovery process to identify the correct key material; it must never reveal the password or make guessing easier. “Payroll production key, rotation 2026-Q3” is already too revealing if an attacker can see it. Prefer opaque key identifiers that map to protected key-vault metadata.

Password protection means more than hiding literals. Prevent passwords from reaching application logs, SQL traces, terminal scrollback, dump data, source control, and diagnostic tickets. Restrict who can run a decrypting package. Design for rotation before the first insert: record a non-secret key version with each encrypted value, retain old decrypt capability only for the migration window, and re-encrypt in controlled batches.

Encrypted data sets and transparent protection

Db2 table spaces, logs, image copies, and related data sets are z/OS data sets. Platform encryption can protect those data sets without requiring an application to call ENCRYPT for every row. The exact implementation depends on your z/OS release, storage policy, hardware cryptography, and enterprise key manager. Db2 DBAs must work with storage and security teams: a database recovery plan is incomplete if a restored encrypted data set cannot obtain its key.

This is often described as transparent data encryption because applications keep issuing normal SQL. Transparent does not mean invisible operationally: encryption can affect allocation standards, copy/restore testing, key backup, and incident procedures. Test REORG, COPY, RECOVER, disaster recovery, and cloned environments with the same key-access controls you expect in production.

TLS, DDF encryption, and authentication

DDF encryption protects DRDA, JDBC, ODBC, and native REST traffic. In many z/OS deployments AT-TLS supplies TLS around the Db2 port, using RACF-managed certificates and policy rules. Verify the client validates the server certificate; encryption without hostname and chain validation invites a man-in-the-middle attack. Choose modern protocol and cipher policy centrally instead of letting every application select weak defaults.

TLS encryption does not authenticate or authorize SQL by itself. Db2 still evaluates the connection identity, trusted context, package EXECUTE privilege, and table privileges. For REST, use approved HTTP authentication or client certificates, then grant narrowly scoped package authority. Protect credentials with TLS so Basic authentication or PassTickets are not exposed on the network.

  • Use TLS for every external and cross-network DDF endpoint.
  • Rotate certificates before expiry and rehearse trust-store changes.
  • Separate certificate identity, Db2 authorization identity, and key-encryption-key ownership.

RACF integration and key management

RACF integration provides the identity and access-control foundation for Db2 and often protects key rings, certificates, started tasks, and sensitive data sets. Db2 privileges should follow least privilege: a package that decrypts payroll values should not be executable by every reporting role. Audit both RACF decisions and Db2 authorization failures so an attempted decrypt is explainable later.

Key management is the hard part of encryption. Assign key owners, backup/recovery custodians, rotation frequency, revocation steps, and an emergency contact. Store keys separately from ciphertext. Track key identifiers and algorithm decisions in configuration records, not in a developer wiki. Older password-based algorithms have limitations and may be deprecated or unsuitable for current cryptographic policy; confirm supported algorithms and quantum-safe direction with IBM and your security organization before a new design.

Explain It Like I'm Five

Think of a Db2 system as a school. TLS is a locked school bus so nobody reads notes while they travel. Encrypted data sets are locked filing cabinets. Column encryption puts a small locked box around one especially private note. RACF is the badge checker. Keys are the keys to all the locks, so they must be guarded even more carefully than the notes.

Exercises

  1. Classify a customer address, a tax identifier, and an image copy by their in-transit, at-rest, and in-use protections.
  2. Rewrite the SET ENCRYPTION PASSWORD example so the value never appears as a SQL literal.
  3. Create a key-rotation checklist that includes recovery testing and retiring old key access.
  4. Explain why TLS does not remove the need for Db2 package EXECUTE authority.
  5. Ask storage and security teams which encrypted-data-set controls apply to your test subsystem.

Quiz

Test Your Knowledge

1. What does SET ENCRYPTION PASSWORD set?

  • A RACF password
  • A session value used by password-based SQL encryption functions
  • A TLS certificate
  • A Db2 subsystem parameter

2. What does TLS protect for DDF?

  • Only table space pages
  • Data moving across the connection
  • Only Db2 catalog rows
  • Only RACF profiles

3. Why track a key version with encrypted data?

  • To expose the key
  • To support controlled key rotation and decryption of older data
  • To avoid backups
  • To bypass RACF

Frequently Asked Questions