X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id D3AC79FA293 for ; Thu, 18 May 2006 10:13:48 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 26946-10 for ; Thu, 18 May 2006 10:13:42 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id B9E4D9F9C18 for ; Thu, 18 May 2006 10:13:43 -0300 (ADT) Received: from druid.net (druid.net [66.96.28.249]) by svr4.postgresql.org (Postfix) with ESMTP id CC2375B7502 for ; Thu, 18 May 2006 13:13:41 +0000 (GMT) Received: from dilbert (H245.C18.B96.tor.eicat.ca [66.96.18.245]) by druid.net (Postfix) with SMTP id F2117B4B7; Thu, 18 May 2006 09:13:40 -0400 (EDT) Date: Thu, 18 May 2006 09:13:39 -0400 From: "D'Arcy J.M. Cain" To: Michael Fuhr Cc: kthusi@yahoo.com, pgsql-sql@postgresql.org Subject: Re: Encryption functions Message-Id: <20060518091339.249bf054.darcy@druid.net> In-Reply-To: <20060518124455.GA8583@winnie.fuhr.org> References: <20060518112119.85801.qmail@web30406.mail.mud.yahoo.com> <20060518124455.GA8583@winnie.fuhr.org> X-Mailer: Sylpheed version 2.2.4 (GTK+ 2.8.12; i386--netbsdelf) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/139 X-Sequence-Number: 25170 On Thu, 18 May 2006 06:44:55 -0600 Michael Fuhr wrote: > On Thu, May 18, 2006 at 04:21:19AM -0700, Thusitha Kodikara wrote: > > Are there any encryption functions that can be used in > > SQL inserts and selects directly? For example like > > "select encryptin_function('test_to_be_encrypted'), ........" > > See the contrib/pgcrypto module. It has functions like digest() > for making SHA1, MD5, and other digests; hmac() for making Hashed > Message Authentication Codes; and encrypt()/encrypt_iv() and > decrypt()/decrypt_iv() for doing encryption and decryption. Since > 8.1 pgcrypto also has functions for doing OpenPGP symmetric and > public-key encryption. If your requirements are simpler check out the genpass module. It is a DES3 encrypted type. You can do things like "SELECT * FROM table WHERE passw = 'hello'" and it will find passwords that are entered as 'hello' even though they are stored encrypted. Example: darcy=# select 'hello'::chkpass; chkpass ---------------- :v1L3NdWy0OHlQ (1 row) darcy=# select ':v1L3NdWy0OHlQ'::chkpass = 'hello'; ?column? ---------- t (1 row) darcy=# select ':v1L3NdWy0OHlQ'::chkpass = 'nothello'; ?column? ---------- f (1 row) Note that the leading colon says that the string is already encrypted. This allows dump and restore to work correctly. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.