store data files encryptypted in database.

This is a multi-part message in MIME format.

------=_NextPart_000_0003_01C92AD4.42102F00
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

hi, i'm trying to store data files encryptypted in postgres 8.1 database =
but i can`t make it works.
this is what i'm doing.

$link =3D pg_connect("host=3D$dbhost user=3D$dbuser password=3D$dbpwd =
dbname=3D$dbname") or die(pg_last_error($link));
$fp =3D fopen($tmp_name, "rb");
$file=3D fread($fp, filesize($tmp_name));
fclose($fp);
$file=3Dpg_escape_bytea($file);
$sql =3D "INSERT INTO SOME_TABLE (bytea_file) VALUES =
(pgp_sym_decrypt_bytea($file,somepass,cipher-algo=3Daes256)) ";
pg_query($link, $sql) or die(pg_last_error($link));

this error appear...

ERROR: column "content_of_bytea_file" does not exist ( =
"content_of_bytea_file" is $file)

it seems that whant to the $file be a column ... but thats not what the =
documentation says...


F.20.3.2. pgp_sym_decrypt()
pgp_sym_decrypt(msg bytea, psw text [, options text ]) returns text
pgp_sym_decrypt_bytea(msg bytea, psw text [, options text ]) returns =
bytea
Decrypt a symmetric-key-encrypted PGP message.

Decrypting bytea data with pgp_sym_decrypt is disallowed. This is to =
avoid outputting invalid character data. Decrypting originally textual =
data with pgp_sym_decrypt_bytea is fine.

The options parameter can contain option settings, as described below.



F.20.3.7. Options for PGP functions
Options are named to be similar to GnuPG. An option's value should be =
given after an equal sign; separate options from each other with commas. =
For example:

pgp_sym_encrypt(data, psw, 'compress-algo=3D1, =
cipher-algo=3Daes256')
All of the options except convert-crlf apply only to encrypt =
functions. Decrypt functions get the parameters from the PGP data.

The most interesting options are probably compress-algo and =
unicode-mode. The rest should have reasonable defaults.



thanks

------=_NextPart_000_0003_01C92AD4.42102F00
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2180" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>hi, i'm trying to store data files =
encryptypted in
postgres 8.1 database but i can`t make it works.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>this is what i'm doing.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>$link =3D pg_connect("host=3D$dbhost =
user=3D$dbuser
password=3D$dbpwd dbname=3D$dbname") or =
die(pg_last_error($link));</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>$fp =3D fopen($tmp_name, =
"rb");</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>$file=3D fread($fp,
filesize($tmp_name));<BR>fclose($fp);</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>$file=3Dpg_escape_bytea($file);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>$sql =3D "INSERT INTO SOME_TABLE
(bytea_file)  VALUES
(pgp_sym_decrypt_bytea($file,somepass,cipher-algo=3Daes256)) ";   =
;    
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>pg_query($link, $sql) or
die(pg_last_error($link));</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>this error appear...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV>ERROR: column "content_of_bytea_file" does not
exist     ( "content_of_bytea_file" is $file)</DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>it seems that whant to =
the $file be a
column ... but thats not what the documentation says...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV class=3DSECT3>
<H3 class=3DSECT3><A name=3DAEN102072>F.20.3.2. <CODE
class=3DFUNCTION>pgp_sym_decrypt()</CODE></A></H3><PRE class=3DSYNOPSIS> =
pgp_sym_decrypt(msg bytea, psw text [, options text ]) returns text
pgp_sym_decrypt_bytea(msg bytea, psw text [, options text ]) returns =
bytea
</PRE>
<P>Decrypt a symmetric-key-encrypted PGP message. </P>
<P>Decrypting bytea data with <CODE =
class=3DFUNCTION>pgp_sym_decrypt</CODE> is
disallowed. This is to avoid outputting invalid character data. =
Decrypting
originally textual data with <CODE =
class=3DFUNCTION>pgp_sym_decrypt_bytea</CODE>
is fine. </P>
<P>The <TT class=3DPARAMETER>options</TT> parameter can contain option =
settings,
as described below. </P>
<P> </P>
<H3 class=3DSECT3><A name=3DAEN102128>F.20.3.7. Options for PGP =
functions</A></H3>
<P>Options are named to be similar to GnuPG. An option's value should be =
given
after an equal sign; separate options from each other with commas. For =
example:
</P><PRE class=3DPROGRAMLISTING> pgp_sym_encrypt(data, psw, =
'compress-algo=3D1, cipher-algo=3Daes256')
</PRE>
<P>All of the options except <TT class=3DLITERAL>convert-crlf</TT> apply =
only to
encrypt functions. Decrypt functions get the parameters from the PGP =
data. </P>
<P>The most interesting options are probably <TT
class=3DLITERAL>compress-algo</TT> and <TT =
class=3DLITERAL>unicode-mode</TT>. The
rest should have reasonable defaults. </P>
<P> </P>
<P>thanks</FONT></P></DIV></DIV></BODY></HTML>

------=_NextPart_000_0003_01C92AD4.42102F00--
elmarkivp [ Fr, 10 Oktober 2008 17:32 ] [ ID #1972679 ]

Re: store data files encryptypted in database.

On 10/10/2008 16:32, elmarkivp wrote:
> $sql = "INSERT INTO SOME_TABLE (bytea_file) VALUES
> (pgp_sym_decrypt_bytea($file,somepass,cipher-algo=aes256))";
> pg_query($link, $sql) or die(pg_last_error($link));
>
> this error appear...
>
> ERROR: column "content_of_bytea_file" does not exist (
> "content_of_bytea_file" is $file)

At a guess, you need to quote the contents of $file in order to get PG
to treat it as a string. If you don't, PG sees it as a column name,
hence the error you're seeing.

Ray.

------------------------------------------------------------ ------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod [at] iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------ ------

--
Sent via pgsql-php mailing list (pgsql-php [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
Rod [ Fr, 10 Oktober 2008 17:39 ] [ ID #1972680 ]

Re: store data files encryptypted in database.

i have quoted $file and now thi is what happend...

$sql = "INSERT INTO SOME_TABLE (bytea_file) VALUES
(pgp_sym_decrypt_bytea('$file','somepass','cipher-algo=aes25 6'))";

ERROR: function pgp_sym_encrypt_bytea("unknown", "unknown", "unknown") does
not exist HINT: No function matches the given name and argument types. You
may need to add explicit type casts

so... with

$sql = "INSERT INTO SOME_TABLE (bytea_file) VALUES
(pgp_sym_decrypt_bytea('$file'::bytea,'somepass'::text,'ciph er-algo=aes256'::text))";

ERROR: function pgp_sym_encrypt_bytea(bytea, text, text) does not exist
HINT: No function matches the given name and argument types. You may need to
add explicit type casts.

any idea?


----- Original Message -----
From: "Raymond O'Donnell" <rod [at] iol.ie>
To: "elmarkivp" <elmarkivo [at] hotmail.com>
Cc: <pgsql-php [at] postgresql.org>
Sent: Friday, October 10, 2008 12:39 PM
Subject: Re: [PHP] store data files encryptypted in database.


> On 10/10/2008 16:32, elmarkivp wrote:
>> $sql = "INSERT INTO SOME_TABLE (bytea_file) VALUES
>> (pgp_sym_decrypt_bytea($file,somepass,cipher-algo=aes256))";
>> pg_query($link, $sql) or die(pg_last_error($link));
>>
>> this error appear...
>>
>> ERROR: column "content_of_bytea_file" does not exist (
>> "content_of_bytea_file" is $file)
>
> At a guess, you need to quote the contents of $file in order to get PG
> to treat it as a string. If you don't, PG sees it as a column name,
> hence the error you're seeing.
>
> Ray.
>
> ------------------------------------------------------------ ------
> Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
> rod [at] iol.ie
> Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
> ------------------------------------------------------------ ------
>
> --
> Sent via pgsql-php mailing list (pgsql-php [at] postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-php
>


--
Sent via pgsql-php mailing list (pgsql-php [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
elmarkivp [ Fr, 10 Oktober 2008 18:10 ] [ ID #1972681 ]

Re: store data files encryptypted in database.

elmarkivp wrote:
>
> i'm trying to store data files encryptypted in postgres 8.1 database
>
> F.20.3.2. |pgp_sym_decrypt()|
>
> pgp_sym_decrypt(msg bytea, psw text [, options text ]) returns text
> pgp_sym_decrypt_bytea(msg bytea, psw text [, options text ]) returns bytea



You quote the 8.3 docs; yet you are running 8.1

These functions are not in 8.1

--
Sent via pgsql-php mailing list (pgsql-php [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
Frank Bax [ Fr, 10 Oktober 2008 18:26 ] [ ID #1972682 ]

Re: store data files encryptypted in database.

--xexMVKTdXPhpRiVT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello X,

Am 2008-10-10 12:32:28, schrieb elmarkivp:
> hi, i'm trying to store data files encryptypted in postgres 8.1 database =
but i can`t make it works.
> this is what i'm doing.
>
> $link =3D pg_connect("host=3D$dbhost user=3D$dbuser password=3D$dbpwd dbn=
ame=3D$dbname") or die(pg_last_error($link));
> $fp =3D fopen($tmp_name, "rb");
> $file=3D fread($fp, filesize($tmp_name));
> fclose($fp);
> $file=3Dpg_escape_bytea($file);
> $sql =3D "INSERT INTO SOME_TABLE (bytea_file) VALUES (pgp_sym_decrypt_by=
tea($file,somepass,cipher-algo=3Daes256))";
^^^^^^^^^^^^

> ERROR: column "content_of_bytea_file" does not exist ( "content_of_by=
tea_file" is $file)
^^^^^^^^^^^^^^^^^^^^^^^

There are two different columns.
I think, you should RECHECK your PHP script.

Greetings
Michelle Konzack
Systemadministrator
24V Electronic Engineer
Tamay Dogan Network
Debian GNU/Linux Consultant


--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
+49/177/9351947 50, rue de Soultz MSN LinuxMichi
+33/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com)

--xexMVKTdXPhpRiVT
Content-Type: application/pgp-signature; name="signature.pgp"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFI8LwqC0FPBMSS+BIRAh5aAJ9NcIynh7Ax4fUiheee8b0IXfZcRwCc C/sx
jhN+FuAA2uQ4kJCpZUBArAg=
=g3tf
-----END PGP SIGNATURE-----

--xexMVKTdXPhpRiVT--
Michelle Konzack [ Sa, 11 Oktober 2008 16:46 ] [ ID #1972973 ]
Datenbanken » gmane.comp.db.postgresql.php » store data files encryptypted in database.

Vorheriges Thema: storing binary files / memory limit
Nächstes Thema: ERROR: relation "userroles" does not exist