Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fWHhi-0007Ci-MB for pgsql-general@arkaria.postgresql.org; Fri, 22 Jun 2018 08:46:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fWHhf-0003TU-Pf for pgsql-general@arkaria.postgresql.org; Fri, 22 Jun 2018 08:45:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fWHhf-0003TN-ID for pgsql-general@lists.postgresql.org; Fri, 22 Jun 2018 08:45:59 +0000 Received: from evolu-s.it ([94.23.66.144] helo=smtp.evolu-s.it) by magus.postgresql.org with smtp (Exim 4.89) (envelope-from ) id 1fWHhc-00026l-U1 for pgsql-general@lists.postgresql.org; Fri, 22 Jun 2018 08:45:59 +0000 Received: from [192.168.1.163] ([79.6.30.247]) by smtp.evolu-s.it ; Fri, 22 Jun 2018 10:45:54 +0200 Subject: Re: pgp_sym_decrypt() - error 39000: wrong key or corrupt data To: pgsql-general@lists.postgresql.org References: <1d7de609-5738-bf51-f0b9-b32a889f04e1@evolu-s.it> <94ecaa31-5960-6264-81f9-c8560a3f9fed@aklaver.com> From: Moreno Andreo Message-ID: Date: Fri, 22 Jun 2018 10:46:01 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <94ecaa31-5960-6264-81f9-c8560a3f9fed@aklaver.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 8bit Content-Language: it List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Il 21/06/2018 23:31, Adrian Klaver ha scritto: > On 06/21/2018 08:36 AM, Moreno Andreo wrote: >> Hi, >>      while playing with pgcrypto I ran into a strange issue >> (postgresql 9.5.3 x86 on Windows 7) >> >> Having a table with a field >> dateofbirth text >> >> I made the following sequence of SQL commands >> update tbl_p set dateofbirth = pgp_sym_encrypt('2018-06-21', >> 'AES_KEY') where codguid = '00000001-0001-0001-0001-000000000001'; >> OK >> >> select pgp_sym_decrypt(dateofbirth::bytea, 'AES_KEY') as datanasc >> from tbl_p where codguid = '00000001-0001-0001-0001-000000000001' >> '2018-06-21' >> >> select * from tab_paz where pgp_sym_decrypt(natoil::bytea, 'AES_KEY') >> = '2018-06-21' > > You switched gears above. > > What is the data type of the natoil field in table tab_paz? Sorry, just a typo... natoil is, actually dateofbirth, so it's text. You can read it as select * from tbl_p where pgp_sym_decrypt(dateofbirth::bytea, 'AES_KEY') = '2018-06-21' > > Was the data encrypted in it using the 'AES_KEY'? Yes, the command sequence is exactly reported above. If I use pgp_sym_decrypt in a SELECT statement it's OK, but if it's in a where clause it seems not to be working.