pgp_pub_decrypt function fails after upgrade from PostgreSQL 12 to PostgreSQL 15

156 views Asked by At

I have a weird behaviour after upgrading our database server from Postgresql 12 to Postgresql 15. I created all the required extensions with pgcrypto even the same version 1.3. It looks like the pgp decryption function with pgp_pub_decrypt works differently. I am using two functions to encypt and decrypt messages:

encode(pgp_pub_encrypt(toencode, dearmor(PGPPublic)), 'hex');

pgp_pub_decrypt(decode(todecode ,'hex'), dearmor(PGPPrivate), 'banana');

It works for years with Postgresql 12 but now with Postgresql 15 I get the error message: "Wrong key or corrupt data"

I compared the results from decode, dearmor and encode and they all behave the same. The public and private key are also exactly the same on both systems.

I checked the documentation and there are no changes I can see and I can't find any other help.

Just pgp_pub_decrypt(decode(todecode ,'hex'), dearmor(PGPPrivate), 'banana'); causes problems

1

There are 1 answers

2
Niels On

I just recreated the pgp keys on the new machine and swapped them in the stored procedure. That seems to work. Perhaps it was related to a different OpenPGP version on the new db server? Shouldn't be but it works now ;-)