X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id ECB1D53503 for ; Mon, 11 Apr 2005 19:26:25 -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 99338-01 for ; Mon, 11 Apr 2005 22:26:23 +0000 (GMT) Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net [24.249.201.67]) by svr1.postgresql.org (Postfix) with ESMTP id A297C5350D for ; Mon, 11 Apr 2005 19:26:20 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO [172.16.1.115]) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 2747040; Mon, 11 Apr 2005 16:25:28 -0700 Message-ID: <425AF98E.3030004@joeconway.com> Date: Mon, 11 Apr 2005 15:26:22 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.6) Gecko/20050323 Fedora/1.7.6-1.3.2 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Moran.Michael" Cc: PostgreSQL Subject: Re: PGCrypto: Realworld scenario and advice needed References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.048 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200504/155 X-Sequence-Number: 21048 Moran.Michael wrote: > My initial attack plan was to do the following: > > 1. Call decrypt() with the old-passphrase to decrypt each table's existing > data. > 2. Temporarily store the decrypted data in temp tables. > 3. Delete all rows of encrypted data from the original tables -- thereby > clearing the tables of all data encrypted with the old passphrase. > 4. Call encrypt() with the new passphrase to encrypt all data in the temp > tables -- thereby repopulating the production tables with data encrypted > with the new passphrase. > 5. Blow away the temp tables. > > But this seems like a tedious procedure. > > Is there any simple way to update ALL existing encrypted data with a new > passphrase, assuming you know the old passphrase and encryption type (i.e. > AES, Blowfish, etc.) without having to go through the 5-step process > mentioned above? Why not use a single UPDATE command, e.g. something like: UPDATE tbl SET f1 = encrypt(decrypt(f1, 'oldkey', 'aes'), 'newkey', 'aes'); Joe