Encryption Test

All we need is an easy explanation of the problem, so here it is.

I’m using PostgreSQL-11 and I’ve been given a text string to decrypt as a test. I’ve got the details of how it was encrypted and its very simple. When I try to decrypt using select pgp_sym_decrypt(text::bytea,'the key','cipher-algo=aes256') I get the error Wrong key or corrupt data. I can’t use the decrypt function because I get the error cipher algorithm is not available.
What am I doing wrong?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

If you are using the format specified by PGP, then the algo used for encryption is stored in the header, and that of course will be used for decryption. Trying to manually specify a algo to use for decryption is pointless.

Here is a working example of encryption and decryption:

select pgp_sym_decrypt(
    pgp_sym_encrypt('foobar','the key','cipher-algo=aes256'),
    'the key'
);

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

Leave a Reply