pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: John Tregea <john@debraneys.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Storing encrypted data?
Date: Sun, 16 Jul 2006 21:07:05 -0600
Message-ID: <20060717030705.GA87022@winnie.fuhr.org> (raw)
In-Reply-To: <44BAE3B0.8060403@debraneys.com>
References: <A70AE049E81A6A40879D5DC0AC8C38C9069508ED@venus.infics.com>
	<44BAE3B0.8060403@debraneys.com>

On Mon, Jul 17, 2006 at 09:11:12AM +0800, John Tregea wrote:
> Does anyone have experience with storing encrypted data into pgSQL? I 
> have a pgSQL database which uses UTF8 encoding. I am encrypting plain 
> text in my (GUI) application and sending it to a field (with data type 
> 'text') in my database.
> 
> I get an error back saying "invalid byte sequence for encoding UTF8; oxd733"

Use bytea instead of text for binary data; alternatively, base64
encode ("armor") the encrypted data and store it as text.  If you
insert binary data then you'll need to escape non-printable characters
or use an API that can pass binary data to the backend (e.g., libpq's
PQexecParams() or some language's interface to that function).  Some
APIs might automatically escape data if you use placeholders; check
your API's documentation.

http://www.postgresql.org/docs/8.1/interactive/datatype-binary.html
http://www.postgresql.org/docs/8.1/interactive/libpq-exec.html

-- 
Michael Fuhr



view thread (8+ messages)  latest in thread

Message-ID: <20060717030705.GA87022@winnie.fuhr.org>
Permalink:  ../20060717030705.GA87022@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20060717030705.GA87022@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mike@fuhr.org, john@debraneys.com
  Subject: Re: Storing encrypted data?
  In-Reply-To: <20060717030705.GA87022@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox