Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oi1dU-0006cX-O8 for pgsql-general@arkaria.postgresql.org; Mon, 10 Oct 2022 22:52:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oi1dT-0000tx-II for pgsql-general@arkaria.postgresql.org; Mon, 10 Oct 2022 22:52:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oi1dT-0000to-7U for pgsql-general@lists.postgresql.org; Mon, 10 Oct 2022 22:52:35 +0000 Received: from mout-u-107.mailbox.org ([2001:67c:2050:101:465::107]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oi1dQ-0002T5-Rj for pgsql-general@lists.postgresql.org; Mon, 10 Oct 2022 22:52:34 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4MmZ1S203Kz9sSr; Tue, 11 Oct 2022 00:52:28 +0200 (CEST) Date: Tue, 11 Oct 2022 00:52:27 +0200 (CEST) From: Erik Wienhold To: howardnews@selestial.com, Pgsql General Message-ID: <1927905082.230328.1665442347383@office.mailbox.org> In-Reply-To: <21bd2e636ddba3214539cf26243d6708@selestial.com> References: <21bd2e636ddba3214539cf26243d6708@selestial.com> Subject: Re: Playing with pgcrypto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Howard, > On 11/10/2022 00:25 CEST howardnews@selestial.com wrote: > > I am trying out a few pgcrypto functions. I was expecting the final > select statement to return the row I just inserted - Can anyone tell me > what I am not understanding here? > > create table test (p1 bytea); > insert into test (pgp_sym_encrypt('123', 'secret')); Your INSERT is malformed. It's missing a VALUES clause or SELECT. > select * from test where pgp_sym_encrypt('123', 'secret') = p1; pgp_sym_encrypt uses a random salt each time, so you cannot compare the output to p1 like you would do with crypt to verify a given plaintext. Instead, use pgp_sym_decrypt with p1 as input to get the plaintext. -- Erik