encrypt/decrypt between javascript and postgresql.

From: AC Gomez <antklc(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: encrypt/decrypt between javascript and postgresql.
Date: 2020-03-12 00:46:20
Message-ID: CABtmK-iBHA5VVa4zYVLtwUdYq_1D4QmjUvwTHW_Hd8gG7FW=wg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm trying to encrypt/decrypt between javascript and postgresql.

I'm using this:
https://gist.github.com/vlucas/2bd40f62d20c1d49237a109d491974eb algorithm
to encrypt my text, and then in PostgreSQL I use PGCRYPTO.decrypt_iv to
decrypt the text.

I pass in 'ThisISMySign' to the Encrypt function.

Encrypted string returned from
above: "fc9a03cbc8a57d4061570575f197c29c:a319a4bf354516f392ba96a895478af6"

I have to remove the colon to get something out...and so this:

select
decrypt_iv(decode('fc9a03cbc8a57d4061570575f197c29ca319a4bf354516f392ba96a895478af6','hex')::bytea,
'sKCx49VgtHZ59bJOTLcU0Gr06ogUnDJi'::bytea, 'null'::bytea,
'aes-cbc/pad:pkcs');

Gives me this: 6 á¶ðÒÿÆÛÏBSïÅThisISMySign

"ThisISMySign" was the original string. So I'm getting the right result in
half of the decrypted string.

The paremeter after the key, 3rd parameter, it can be any string. That just
changes the first part of the output, the garbage part.

In decrypt_iv I tried using the encryption algorithm name in the javascript
used to encrypt, but that gets me nowhere.

I cannot see what i'm missing here.

Thanks

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Virendra Kumar 2020-03-12 01:16:10 Re: Back Port Request for INVALID Startup Packet
Previous Message Tom Lane 2020-03-12 00:29:27 Re: Back Port Request for INVALID Startup Packet