Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Overview of this book

Table of Contents (19 chapters)
PostgreSQL 9 Administration Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Encrypting sensitive data


This recipe shows you how to encrypt data using the pgcrypto contrib package.

Getting ready

Make sure you (and/or your database server) are in a country where encryption is not illegal—it still is in some countries.

In order to create and manage PGP keys, you also need the well-known GnuPG command-line utility, which is available on practically all distributions.

Make sure that pgcrypto is installed on your database host. On Debian and Ubuntu, it comes with the postgresql-contrib -9. 4 package (change 9.4 for other PostgreSQL versions).

Install it on the database in which you want to use it, following the Adding an external module to PostgreSQL recipe from Chapter 3, Configuration.

You also need to have PGP keys set up:

pguser@laptop:~$ gpg --gen-key

Answer some questions here (defaults are OK unless you are an expert), select the key type as DSA and Elgamal, and enter an empty password.

Now, export the keys:

pguser@laptop:~$ gpg -a --export "PostgreSQL User (test key...