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 1fW7Aw-0000Nh-R5 for pgsql-general@arkaria.postgresql.org; Thu, 21 Jun 2018 21:31:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fW7Au-0003DK-Qy for pgsql-general@arkaria.postgresql.org; Thu, 21 Jun 2018 21:31:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fW7At-0003DD-0Q for pgsql-general@lists.postgresql.org; Thu, 21 Jun 2018 21:31:28 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fW7Al-0002Ec-FB for pgsql-general@postgresql.org; Thu, 21 Jun 2018 21:31:25 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id DCB4521BF8; Thu, 21 Jun 2018 17:31:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 21 Jun 2018 17:31:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=AnL3VriGYZQhk65xlpCeTuqKSCj8o 3u9ND5JnMWyQiM=; b=WkOLmNkmzLo/Pf0gHcfrC2e1VJ/xgezQ1AXnmCGikos0m DQEet7WScpaf6fVfFRhFAv5K5kvYgQnXVdomJYrr/4Ay52iUDtdakmd9f13itNH0 RQoUkfn8aUx17xKyrm6MGVuL7iRZGX1nFWamYlFhRBnJRRCbtmnwkdLDjz8t3QCV 9UbpSj1+nvn4tUBNqQRd4STb8KgX6A5mSQOEEttlozENH+Y4bBFA1Il5Oyqk2meC NBtx3ZMN8ukIMAiYihAYxK620c0Hg319Cw7XIBP25+3Fwdub5WjYVbyD0I5ZKhFP aU+skfcCHH30l2T46ckmMqhwk+LrAiNJ/okgV8bhw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=AnL3Vr iGYZQhk65xlpCeTuqKSCj8o3u9ND5JnMWyQiM=; b=OTZEND64dfyGKryjXAzrW8 UUeqq+HuzE3YBsIh0Nib4rqnVsHhRg8DBZjbd67oNAK/QgOcRRU5l81Wd8/lN2Xb yyBotlUpnRIz2cpgH7CVILTTLA8Ix4+S2Y1NEL0VJ+BxkPrjweo5rwyhsG0ShxXJ 14tJ9vIQPTxntfsqYyeai3yIv0GZAcVeGHIyMKNTWY3ZuEoXkyP04kT3tPaRoo2k Nnjfz2wvsgdcmXbq83C3O77HbNM5u2tc5kQ0n5T0oH6BJ9tJeNpA6k+2YjanCgwg ynquDrt+viBPCqZJ1odyyfjh5ZV+8RnxWLYaQgh/n/hG+j9a8wELT0h3O38/7gow == X-ME-Proxy: X-ME-Sender: Received: from ranger.suse (c-73-239-117-238.hsd1.wa.comcast.net [73.239.117.238]) by mail.messagingengine.com (Postfix) with ESMTPA id 456881025C; Thu, 21 Jun 2018 17:31:17 -0400 (EDT) Subject: Re: pgp_sym_decrypt() - error 39000: wrong key or corrupt data To: Moreno Andreo , PostgreSQL mailing lists References: <1d7de609-5738-bf51-f0b9-b32a889f04e1@evolu-s.it> From: Adrian Klaver Message-ID: <94ecaa31-5960-6264-81f9-c8560a3f9fed@aklaver.com> Date: Thu, 21 Jun 2018 14:31:16 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <1d7de609-5738-bf51-f0b9-b32a889f04e1@evolu-s.it> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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? Was the data encrypted in it using the 'AES_KEY'? I can replicate the below by doing: select pgp_sym_decrypt(pgp_sym_encrypt('2018-06-21', 'AES_KEY'), 'AES'); ERROR: Wrong key or corrupt data > ERROR:  Wrong key or corrupt data > ********** Error ********** > > ERROR: Wrong key or corrupt data > SQL state: 39000 > > Can't find reference anywhere... > Any help would be appreciated. > Thanks, > Moreno.- > > > -- Adrian Klaver adrian.klaver@aklaver.com