X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 1A50D9FB1BB for ; Mon, 17 Jul 2006 09:17:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 23684-02 for ; Mon, 17 Jul 2006 12:17:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 7E09F9FB1B8 for ; Mon, 17 Jul 2006 09:17:01 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.7/8.13.7) with ESMTP id k6HCGp8Y005045 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 17 Jul 2006 06:16:54 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.6/8.13.6) with ESMTP id k6HCGp5m003700; Mon, 17 Jul 2006 06:16:51 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.6/8.13.6/Submit) id k6HCGpPx003699; Mon, 17 Jul 2006 06:16:51 -0600 (MDT) (envelope-from mfuhr) Date: Mon, 17 Jul 2006 06:16:50 -0600 From: Michael Fuhr To: John Tregea Cc: pgsql-sql@postgresql.org Subject: Re: Storing encrypted data? Message-ID: <20060717121650.GA3571@winnie.fuhr.org> References: <44BAE3B0.8060403@debraneys.com> <20060717030705.GA87022@winnie.fuhr.org> <44BB28AC.3070302@debraneys.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44BB28AC.3070302@debraneys.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/225 X-Sequence-Number: 25799 On Mon, Jul 17, 2006 at 02:05:32PM +0800, John Tregea wrote: > Thanks for your advice. I was looking at the bytea data type in the > PostgreSQL book I bought (Korry and Susan Douglas, second edition). I > was concerned that if I have to escape certain characters like the > single quote or the backslash, how do I guarantee that the escaped > version does not already appear in the encrypted string? > > Should I use the octal value to escape the single quote (\047) and > backslash (\\134)? Yes, you'll need to escape certain characters like backslashes. Your client API might provide an escaping function so you don't have to worry about the details, or, if you're using placeholders, the API might automatically escape binary data or transfer it to the backend as binary. What client interface will you be using to insert this data? > Those character sequences are extremely unlikely to occur in an > encrypted string. They're as likely to occur as any other. A desirable property of a cipher is that its output should be indistinguishable from random data, so any character or sequence of characters is equally likely to occur. > Also... I note that I cannot change the data type of my field from text > to bytea (I am using PGADMIN III). Do you know why? I don't use pgAdmin so I don't know what it can or can't do. Have you tried it in psql? What version of PostgreSQL are you using? The ability to alter a column's type was added in 8.0; in previous versions you can use the method shown in the FAQ: http://www.postgresql.org/docs/faqs.FAQ.html#item4.3 -- Michael Fuhr