PQunescapebytea not reverse of PQescapebytea? - Mailing list pgsql-interfaces

From Karthik Segpi
Subject PQunescapebytea not reverse of PQescapebytea?
Date
Msg-id CACD7L9GCLsM=wEwwH707sN19dMkMHwHh+ffVmLQdsFXNR0UJ6Q@mail.gmail.com
Whole thread Raw
Responses Re: PQunescapebytea not reverse of PQescapebytea?  (Florian Weimer <fw@deneb.enyo.de>)
List pgsql-interfaces
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 'byte a'.

Has anyone faced this scenario before? 

Thanks-
Karthik





pgsql-interfaces by date:

Previous
From: "Francisco Figueiredo Jr."
Date:
Subject: Npgsql 2.1.0-rc1 released!
Next
From: alexandros_e
Date:
Subject: C++ read int array with libpqxx