PQunescapebytea not reverse of PQescapebytea?

From: Karthik Segpi <karthik(dot)segpi(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: PQunescapebytea not reverse of PQescapebytea?
Date: 2014-03-02 01:29:27
Message-ID: CACD7L9FTet=B=DFwLO1SgaNNukeK6poVxLm524zHtBcmac6ttg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi -
I have a 'bytea' column in the database, onto which my custom C application
is inserting encrypted data. Before inserting, I am calling
'PQescapebytea()' to escape the ciphertext. However, after SELECT, the data
needs to be 'un-escaped' before attempting to decrypt. I am trying to
'un-escape' using 'PQunescapebytea'. However, I am finding that
'PQunescapebytea' is not exact inverse of 'PQescapebytea'. I saw
documentation and posts in the mailing lists alluding to this as well. As a
result, the decryption always fails.

Is there another C method out there that does exact inverse of
'PQescapebytea'? If the answer is no, then what other options do I have? I
could think of the following:

1. Write my own C method that does exactly the inverse of 'PQescapebytea'
2. Instead of using 'PQescapebytea', base64 encode ciphertext before
inserting. Not sure how well this would work.
3. Use 'text' data type for the column instead of 'bytea'.

Has anyone faced this scenario before?

Thanks-
Karthik

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Atkins 2014-03-02 01:31:20 Re: Replacing Ordinal Suffixes
Previous Message George Weaver 2014-03-01 19:45:54 Re: Replacing Ordinal Suffixes