Re: Fwd: How to encrypt a column

From: Jeff Lu <jeff_k_lu(at)yahoo(dot)com>
To: Owen Jacobson <ojacobson(at)osl(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Fwd: How to encrypt a column
Date: 2005-08-11 21:55:20
Message-ID: 20050811215520.38623.qmail@web50609.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


I do get a couple of warnings at compile time:
intrasend.c:496:37: warning: multi-character character constant
intrasend.c:496:44: warning: multi-character character constant
intrasend.c:517:84: warning: character constant too long for its type

Here's what is in the variable "data" = "0018`0018`64045`08112005`64045`1````Discount=0.00;``2``~"

printf("%s", encrypt(data, "foo", "bar"))
prints out (null)

Thank you
Owen Jacobson <ojacobson(at)osl(dot)com> wrote:
Jeff Lu wrote:

> Hi,
>
> I'm interested in encrypting an column in table. Are there any
> example using "C" to create the encrypted column, inserting and
> retreiving data to/from it?
>
> the table is:
> CREATE TABLE mytable (
> id SERIAL PRIMARY KEY,
> crypted_content BYTEA
> );
>
> I'm getting (null) in the field with the following sql statement:
>
> strcpy(data, "data to be encrypted");
> sprintf(query_buff, "insert into mytable values('%s', '%s')", key,

Try printing out the contents of 'query_buff' here. You shouldn't be
getting NULLs in the table, but you may well be getting '' (the empty
string) if encrypt(data, 'foo', 'bar') returns "" or (char *) (0).

> encrypt(data, 'foo', 'bar'));
> PQexec(conn, query_string);

Even better, don't do it this way. This is potentially open to SQL
injection attacks and definitely open to problems with "interesting" values
of key.

Look up PQprepare/PQexecParams for separating the query string from the
values. I use ODBC indirectly, so I can't help you directly, but the docs
at
IN>
should help.

> Another question is can the encrypted column be of type "text" ?

Can't see any reason why not, so long as the encrypted data is represented
as text.

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings


---------------------------------
Start your day with Yahoo! - make it your home page

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Owen Jacobson 2005-08-11 22:09:17 Re: Fwd: How to encrypt a column
Previous Message Hélder M. Vieira 2005-08-11 21:26:13 Re: Fwd: How to encrypt a column