store files encrypted with pgcrypto

This is a multi-part message in MIME format.

------=_NextPart_000_0013_01C93385.CB3B7C30
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi, i'm trying to store files encrypted in postgres 8.3.4, using =
sym_encrypt_bytea function.
this is quoted from the postgres8.3 documentation, thats was my guide, =
below is the php code i have used to make it, with no results and the =
respective errors.

FROM http://www.postgresql.org/docs/8.3/static/pgcrypto.html

F.20.3.1. pgp_sym_encrypt()

pgp_sym_encrypt(data text, psw text [, options text ]) returns bytea
pgp_sym_encrypt_bytea(data bytea, psw text [, options text ]) =
returns bytea


Encrypt data with a symmetric PGP key psw. The options parameter can =
contain option settings, as described below.
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.

THIS IS MY CODE..

<?php
$fp =3D fopen($tmp_name, "rb");
$buffer =3D fread($fp, filesize($tmp_name));
fclose($fp);
$buffer=3Dpg_escape_bytea($buffer);
$sql =3D "INSERT INTO foo(nombre, descripcion, archivo_bytea, mime, =
size) VALUES ('$nombre', '$desc', =
pgp_sym_encrypt_bytea('$buffer',123,'cipher-algo=3Daes256'), '$type', =
$size)";
?>

ERRORS:
ERROR: No function matches the given name and argument types. You =
might need to add explicit type casts
ERROR: function pgp_sym_encrypt_bytea(unknown, integer, unknown) does =
not exist

OTHER CODE WITH EXPLICIT TYPES

<?php
$fp =3D fopen($tmp_name, "rb");
$buffer =3D fread($fp, filesize($tmp_name));
fclose($fp);
$buffer=3Dpg_escape_bytea($buffer);
$sql =3D "INSERT INTO foo(nombre, descripcion, archivo_bytea, mime, =
size) VALUES ('$nombre', '$desc', =
pgp_sym_encrypt_bytea('$buffer'::bytea,123::text,'cipher-alg o=3Daes256'::=
text), '$type', $size)";
?>

ERRORS:
ERROR: function pgp_sym_encrypt_bytea(bytea, text, text) does not =
exist

any help is welcome!



------=_NextPart_000_0013_01C93385.CB3B7C30
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 files encrypted =
in postgres
8.3.4, using sym_encrypt_bytea function.<BR>this is quoted from the =
postgres8.3
documentation, thats was my guide, below is the php code i have used to =
make it,
with no results and the respective errors.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>FROM <A
href=3D"http://www.postgresql.org/docs/8.3/static/pgcrypto.h tml">http://w=
ww.postgresql.org/docs/8.3/static/pgcrypto.html</A></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>F.20.3.1. =
pgp_sym_encrypt()</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>    pgp_sym_encrypt(data =
text, psw
text [, options text ]) returns bytea<BR>   
pgp_sym_encrypt_bytea(data bytea, psw text [, options text ]) returns
bytea<BR>   </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Encrypt data with a symmetric PGP key =
psw. The
options parameter can contain option settings, as described =
below.<BR>F.20.3.2.
pgp_sym_decrypt()</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>    pgp_sym_decrypt(msg =
bytea, psw
text [, options text ]) returns text<BR>   
pgp_sym_decrypt_bytea(msg bytea, psw text [, options text ]) returns
bytea<BR>   </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Decrypt a symmetric-key-encrypted PGP
message.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>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.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>The options parameter can contain =
option settings,
as described below. </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>F.20.3.7. Options for PGP =
functions</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>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:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>    =
pgp_sym_encrypt(data, psw,
'compress-algo=3D1, cipher-algo=3Daes256')<BR>   </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>All of the options except convert-crlf =
apply only
to encrypt functions. Decrypt functions get the parameters from the PGP
data.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>The most interesting options are =
probably
compress-algo and unicode-mode. The rest should have reasonable =
defaults.
</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>THIS IS MY
CODE..<BR> <BR>  <?php<BR>  $fp =3D =
fopen($tmp_name,
"rb");<BR>     $buffer =3D fread($fp,
filesize($tmp_name));<BR>  fclose($fp);<BR>  $buffer=3D=
pg_escape_bytea($buffer);<BR>  $sql
=3D "INSERT INTO foo(nombre, descripcion, archivo_bytea, mime, =
size) VALUES
('$nombre', '$desc', =
pgp_sym_encrypt_bytea('$buffer',123,'cipher-algo=3Daes256'),
'$type', $size)";<BR>  ?></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2>ERRORS:  <BR>  ERROR: No
function matches the given name and argument types. You might need to =
add
explicit type casts <BR>  ERROR: function
pgp_sym_encrypt_bytea(unknown, integer, unknown) does not exist
<BR>  <BR>OTHER CODE WITH EXPLICIT
TYPES<BR>  <BR>  <?php<BR>  $fp =3D
fopen($tmp_name, "rb");<BR>     $buffer =3D =
fread($fp,
filesize($tmp_name));<BR>  fclose($fp);<BR>  $buffer=3D=
pg_escape_bytea($buffer);<BR>  $sql
=3D "INSERT INTO foo(nombre, descripcion, archivo_bytea, mime, =
size) VALUES
('$nombre', '$desc',
pgp_sym_encrypt_bytea('$buffer'::bytea,123::text,'cipher-alg o=3Daes256'::=
text),
'$type', $size)";<BR>  ?></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>ERRORS:<BR>  ERROR: function
pgp_sym_encrypt_bytea(bytea, text, text) does not
exist <BR>  </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>any help is
welcome!<BR>  <BR>  <BR></FONT></DIV></BODY></HTML>

------=_NextPart_000_0013_01C93385.CB3B7C30--
elmarkivp [ Di, 21 Oktober 2008 18:03 ] [ ID #1974048 ]

Re: store files encrypted with pgcrypto

elmarkivp wrote:
> Hi, i'm trying to store files encrypted in postgres 8.3.4, using
> sym_encrypt_bytea function.
> this is quoted from the postgres8.3 documentation, thats was my guide,
> below is the php code i have used to make it, with no results and the
> respective errors.
>
> FROM http://www.postgresql.org/docs/8.3/static/pgcrypto.html
>
> F.20.3.1. pgp_sym_encrypt()
>
> pgp_sym_encrypt(data text, psw text [, options text ]) returns bytea
> pgp_sym_encrypt_bytea(data bytea, psw text [, options text ])
> returns bytea
>
>
> Encrypt data with a symmetric PGP key psw. The options parameter can
> contain option settings, as described below.
> 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
>

<snip>

> ERRORS:
> ERROR: No function matches the given name and argument types. You
> might need to add explicit type casts
> ERROR: function pgp_sym_encrypt_bytea(unknown, integer, unknown) does
> not exist

pgcrypto is a contrib module in pg 8.3 (ie not built in by default). Did
you install the module?

There are instructions on how to do that here:

http://www.postgresql.org/docs/8.3/static/contrib.html

--
Postgresql & php tutorials
http://www.designmagick.com/


--
Sent via pgsql-php mailing list (pgsql-php [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
dmagick [ Di, 21 Oktober 2008 23:56 ] [ ID #1974049 ]
Datenbanken » gmane.comp.db.postgresql.php » store files encrypted with pgcrypto

Vorheriges Thema: apache+php+postgresql+WindowsXP
Nächstes Thema: storing binary files / memory limit