pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
store data files encryptypted in database.
5+ messages / 4 participants
[nested] [flat]

* store data files encryptypted in database.
@ 2008-10-10 15:32  elmarkivp <elmarkivo@hotmail.com>
  0 siblings, 3 replies; 5+ messages in thread

From: elmarkivp @ 2008-10-10 15:32 UTC (permalink / raw)
  To: pgsql-php

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 = pg_connect("host=$dbhost user=$dbuser password=$dbpwd dbname=$dbname") or die(pg_last_error($link));
$fp = fopen($tmp_name, "rb");
$file= fread($fp, filesize($tmp_name));
fclose($fp);
$file=pg_escape_bytea($file);
$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)

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=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. 



thanks

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

* Re: store data files encryptypted in database.
@ 2008-10-10 15:39  Raymond O'Donnell <rod@iol.ie>
  parent: elmarkivp <elmarkivo@hotmail.com>
  2 siblings, 1 reply; 5+ messages in thread

From: Raymond O'Donnell @ 2008-10-10 15:39 UTC (permalink / raw)
  To: elmarkivp <elmarkivo@hotmail.com>; +Cc: pgsql-php

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@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------



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

* Re: store data files encryptypted in database.
@ 2008-10-10 16:10  elmarkivp <elmarkivo@hotmail.com>
  parent: Raymond O'Donnell <rod@iol.ie>
  0 siblings, 0 replies; 5+ messages in thread

From: elmarkivp @ 2008-10-10 16:10 UTC (permalink / raw)
  To: rod@iol.ie; +Cc: pgsql-php

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=aes256'))";

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,'cipher-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@iol.ie>
To: "elmarkivp" <elmarkivo@hotmail.com>
Cc: <pgsql-php@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@iol.ie
> Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
> ------------------------------------------------------------------
>
> -- 
> Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-php
> 




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

* Re: store data files encryptypted in database.
@ 2008-10-10 16:26  Frank Bax <fbax@sympatico.ca>
  parent: elmarkivp <elmarkivo@hotmail.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Frank Bax @ 2008-10-10 16:26 UTC (permalink / raw)
  To: pgsql-php

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



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

* Re: store data files encryptypted in database.
@ 2008-10-11 14:46  Michelle Konzack <linux4michelle@tamay-dogan.net>
  parent: elmarkivp <elmarkivo@hotmail.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Michelle Konzack @ 2008-10-11 14:46 UTC (permalink / raw)
  To: pgsql-php

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 = pg_connect("host=$dbhost user=$dbuser password=$dbpwd dbname=$dbname") or die(pg_last_error($link));
> $fp = fopen($tmp_name, "rb");
> $file= fread($fp, filesize($tmp_name));
> fclose($fp);
> $file=pg_escape_bytea($file);
> $sql = "INSERT INTO SOME_TABLE (bytea_file)  VALUES (pgp_sym_decrypt_bytea($file,somepass,cipher-algo=aes256))";       
                                 ^^^^^^^^^^^^

> ERROR: column "content_of_bytea_file" does not exist     ( "content_of_bytea_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)

Attachments:

  signature.pgp (application/pgp-signature, 188B) download

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


end of thread, other threads:[~2008-10-11 14:46 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-10-10 15:32 store data files encryptypted in database. elmarkivp <elmarkivo@hotmail.com>
2008-10-10 15:39 ` Raymond O'Donnell <rod@iol.ie>
2008-10-10 16:10   ` elmarkivp <elmarkivo@hotmail.com>
2008-10-10 16:26 ` Frank Bax <fbax@sympatico.ca>
2008-10-11 14:46 ` Michelle Konzack <linux4michelle@tamay-dogan.net>

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