pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
store files encrypted with pgcrypto
2+ messages / 2 participants
[nested] [flat]

* store files encrypted with pgcrypto
@ 2008-10-21 16:03 elmarkivp <elmarkivo@hotmail.com>
  2008-10-21 21:56 ` Re: store files encrypted with pgcrypto Chris <dmagick@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: elmarkivp @ 2008-10-21 16:03 UTC (permalink / raw)
  To: pgsql-php

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=1, cipher-algo=aes256')
   

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 = fopen($tmp_name, "rb");
     $buffer = fread($fp, filesize($tmp_name));
  fclose($fp);
  $buffer=pg_escape_bytea($buffer);
  $sql = "INSERT INTO foo(nombre, descripcion, archivo_bytea, mime, size) VALUES ('$nombre', '$desc', pgp_sym_encrypt_bytea('$buffer',123,'cipher-algo=aes256'), '$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 = fopen($tmp_name, "rb");
     $buffer = fread($fp, filesize($tmp_name));
  fclose($fp);
  $buffer=pg_escape_bytea($buffer);
  $sql = "INSERT INTO foo(nombre, descripcion, archivo_bytea, mime, size) VALUES ('$nombre', '$desc', pgp_sym_encrypt_bytea('$buffer'::bytea,123::text,'cipher-algo=aes256'::text), '$type', $size)";
  ?>

ERRORS:
  ERROR: function pgp_sym_encrypt_bytea(bytea, text, text) does not exist 
  
any help is welcome!
  
  

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: store files encrypted with pgcrypto
  2008-10-21 16:03 store files encrypted with pgcrypto elmarkivp <elmarkivo@hotmail.com>
@ 2008-10-21 21:56 ` Chris <dmagick@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Chris @ 2008-10-21 21:56 UTC (permalink / raw)
  To: elmarkivp <elmarkivo@hotmail.com>; +Cc: pgsql-php

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/




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2008-10-21 21:56 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-10-21 16:03 store files encrypted with pgcrypto elmarkivp <elmarkivo@hotmail.com>
2008-10-21 21:56 ` Chris <dmagick@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox