X-Original-To: pgadmin-support-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7FCF6D1B275; Tue, 13 Jul 2004 06:34:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21975-05; Tue, 13 Jul 2004 09:34:57 +0000 (GMT) Received: from nameit.healthnet.lu (nameit.healthnet.lu [158.64.36.4]) by svr1.postgresql.org (Postfix) with ESMTP id CB1F6D1B248; Tue, 13 Jul 2004 06:34:47 -0300 (ADT) Received: from control.dmz.chl.lu (drill.healthnet.lu [158.64.36.2]) by nameit.healthnet.lu (Postfix) with SMTP id 2ABF83E8172; Tue, 13 Jul 2004 11:34:54 +0200 (CEST) Received: from 172.20.1.24 by control.dmz.chl.lu (InterScan E-Mail VirusWall NT); Tue, 13 Jul 2004 11:36:58 +0200 Received: from localhost (pret050pco.inf.chl.lu [172.20.54.5]) by gwia.inf.chl.lu; Tue, 13 Jul 2004 11:34:47 +0200 Date: Tue, 13 Jul 2004 11:35:57 +0200 From: Daniel Struck To: Bruno Wolff III Cc: Sarah Tanembaum , pgsql-php@postgresql.org, pgsql-admin@postgresql.org, pgsql-hackers-win32@postgresql.org, pgadmin-support@postgresql.org, pgsql-sql@postgresql.org Subject: Re: [PHP] Secure DB Systems - How to Message-Id: <20040713113557.31e9d6dc@localhost> In-Reply-To: <20040709152722.GA20935@wolff.to> References: <20040709152722.GA20935@wolff.to> Organization: gwia.inf.chl.lu X-Mailer: Sylpheed version 0.9.11claws (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/47 X-Sequence-Number: 3160 > Keeping the system administrator from seeing the data while making it > searchable is difficult. To do this you need to encrypt the data on > the client side using a key the client has (and this key has to be > protected from loss) and the only searches you can do are equality > searches using a hash or encrypted value. You can also perform regex searches. Here is an example to get you started: CREATE TABLE crypto ( id SERIAL PRIMARY KEY, title VARCHAR(50), crypted_content BYTEA ); INSERT INTO crypto VALUES (1,'test1',encrypt_iv('daniel','fooz',decode('9M= lPeZtpuxKo5m4O4+pd4g=3D=3D','base64'),'aes')); INSERT INTO crypto VALUES (2,'test2',encrypt_iv('test','fooz',decode('9MlP= eZtpuxKo5m4O4+pd4g=3D=3D','base64'),'aes')); INSERT INTO crypto VALUES (3,'test3',encrypt_iv('struck','fooz',decode('9M= lPeZtpuxKo5m4O4+pd4g=3D=3D','base64'),'aes')); SELECT *,decrypt_iv(crypted_content, 'fooz',decode('9MlPeZtpuxKo5m4O4+pd4g= =3D=3D','base64'), 'aes') FROM crypto; -- equality search SELECT *,decrypt_iv(crypted_content,'fooz',decode('9MlPeZtpuxKo5m4O4+pd4g= =3D=3D','base64'),'aes') FROM crypto WHERE decrypt_iv(crypted_content, 'fooz',decode('9MlPeZtpuxKo5m= 4O4+pd4g=3D=3D','base64'), 'aes')=3D'struck'; -- regex search SELECT *,decrypt_iv(crypted_content,'fooz',decode('9MlPeZtpuxKo5m4O4+pd4g= =3D=3D','base64'),'aes') FROM crypto WHERE encode(decrypt_iv(crypted_content, 'fooz',decode('9MlPeZt= puxKo5m4O4+pd4g=3D=3D','base64'), 'aes'),'escape') ~* 'daniel'; "fooz" is the password and "9MlPeZtpuxKo5m4O4+pd4g=3D=3D" is the IV (initia= lization vector) stored in base64 format. I choose base64 because it is mor= e convenient to create queries with it. In the real database I do use a different IV for every row, so I do also st= ore the IV with the row. In my case I do generate the IV by PHP with /dev/urandom as a random source. Greetings, Daniel Struck --=20 Retrovirology Laboratory Luxembourg Centre Hospitalier de Luxembourg 4, rue E. Barbl=E9 L-1210 Luxembourg phone: +352-44116105 fax: +352-44116113 web: http://www.retrovirology.lu e-mail: struck.d@retrovirology.lu