Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2gJP-0003yH-KT for pgsql-general@arkaria.postgresql.org; Tue, 27 Aug 2019 18:35:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i2gJO-0004UI-DG for pgsql-general@arkaria.postgresql.org; Tue, 27 Aug 2019 18:35:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2gJN-0004R9-UY for pgsql-general@lists.postgresql.org; Tue, 27 Aug 2019 18:35:22 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1i2gJL-0007jr-RM for pgsql-general@postgresql.org; Tue, 27 Aug 2019 18:35:20 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1i2gJL-00072L-2a; Tue, 27 Aug 2019 14:35:19 -0400 Date: Tue, 27 Aug 2019 14:35:19 -0400 From: Bruce Momjian To: Jeff Janes Cc: PostgreSQL-general Subject: Re: Matching pgp_sym_encrypt() and gpg2 output Message-ID: <20190827183519.GA29114@momjian.us> References: <20190827173316.GA29115@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="jI8keyz6grp/JLjh" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --jI8keyz6grp/JLjh Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Tue, Aug 27, 2019 at 02:05:28PM -0400, Jeff Janes wrote: > On Tue, Aug 27, 2019 at 1:33 PM Bruce Momjian wrote: > > I am trying to generate output from the command-line program gpg2 that > matches the output of pgp_sym_encrypt().  gpg2 outputs: > >         $ echo 'my access password' | tr -d '\n' | gpg2 --symmetric --batch >         > --cipher-algo AES256 --passphrase 'abc' | xxd -p | tr -d '\n' > > > I don't even get the same output on repeated execution of this same command, so > I think you are pursuing a lost cause. Ah, very good point. I at least get the same first few bytes and same length each time, so I never even looked at the trailing bytes, and you are right that it isn't surprising they differ each time. Anyway, I figured it out. I was originally trying to use openssl to match pgp_sym_encrypt(), and that wasn't working, and then when I couldn't get the gpg2 bytes to match, I asked here. Seems I got it working with the attached SQL file. Thanks. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription + --jI8keyz6grp/JLjh Content-Type: application/x-sql Content-Disposition: attachment; filename="key-pass-test.sql" Content-Transfer-Encoding: quoted-printable CREATE EXTENSION IF NOT EXISTS pgcrypto;=0A=0ASELECT set_config('client_ser= ver.shared_secret',=0A encode(gen_random_bytes(32), 'hex')= , false) AS shared_secret=0A\gset=0A=0A\set access_password 'my access pass= word'=0A=0A\set enc `echo :'access_password' | tr -d '\n' | gpg2 --symmetri= c --batch --cipher-algo AES256 --passphrase :'shared_secret' | xxd -p | tr = -d '\n'`=0A=0ASELECT encode(pgp_sym_decrypt_bytea(decode(:'enc', 'hex'), cu= rrent_setting('client_server.shared_secret'), 'cipher-algo=3Daes256'), 'esc= ape');=0A --jI8keyz6grp/JLjh--