X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id E3551D1DA7E for ; Mon, 12 Jan 2004 11:21:44 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 39584-01 for ; Mon, 12 Jan 2004 07:21:15 -0400 (AST) Received: from neuron.admin.healthnet.lu (drill.healthnet.lu [158.64.36.2]) by svr1.postgresql.org (Postfix) with ESMTP id E976FD1B48D for ; Mon, 12 Jan 2004 07:21:11 -0400 (AST) Received: from control.dmz.chl.lu ([10.11.1.10]) by neuron.admin.healthnet.lu (8.9.3/8.8.8) with SMTP id MAA24886 for ; Mon, 12 Jan 2004 12:15:33 +0100 (MET) Received: from 172.20.1.22 by control.dmz.chl.lu (InterScan E-Mail VirusWall NT); Mon, 12 Jan 2004 11:30:23 +0100 Received: from gentoo.domain.local (pret040pcc.inf.chl.lu [172.20.54.4]) by gwia.inf.chl.lu; Mon, 12 Jan 2004 11:34:22 +0100 Date: Mon, 12 Jan 2004 11:34:21 +0100 From: Daniel Struck To: pgsql-php@postgresql.org Subject: pgcrypto & php Message-Id: <20040112113421.02427893.struck.d@retrovirology.lu> X-Mailer: Sylpheed version 0.9.6claws (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/7 X-Sequence-Number: 2523 Hello, I am storing certain data encrypted by pgcrypto in my database. Here are the commands I use to test the functionality: CREATE TABLE crypto ( id SERIAL PRIMARY KEY, title VARCHAR(50), crypted_content BYTEA ); INSERT INTO crypto VALUES (1,'test1',encrypt('daniel', 'fooz', 'aes')); INSERT INTO crypto VALUES (2,'test2',encrypt('struck', 'fooz', 'aes')); INSERT INTO crypto VALUES (3,'test3',encrypt('konz', 'fooz', 'aes')); SELECT * FROM crypto; SELECT *,decrypt(crypted_content, 'fooz', 'aes') FROM crypto; SELECT *,decrypt(crypted_content, 'fooz', 'aes') FROM crypto WHERE decrypt(= crypted_content, 'fooz', 'aes')=3D'struck'; There are certain occasions where I would like to be able to decrypt/ encry= pt the data in PHP itself. Is this possible with the "Mcrypt Encryption Fun= ctions" of PHP? I have already tried it, by as I am no expert in cryptography, I have diffi= culties finding the right syntax. This is the code I used to try it out: $test=3Dnew db_sql_user; $test->query("select crypted_content from crypto WHERE id=3D1;"); $crypt=3D$test->result(); echo "
"; echo "crypted content from postgresql: " .$crypt; $array =3D unpack("c2chars/nint", $crypt); echo $array; echo "
"; echo mcrypt_decrypt ( MCRYPT_RIJNDAEL_128 , "fooz", $crypt, cbc); echo "
"; echo mcrypt_cbc (MCRYPT_RIJNDAEL_128, "fooz", $crypt , MCRYPT_DECRYPT); This is the output: crypted content from postgresql: g=B0=F1\220399=F9=FB=B9qyg=AE=DB~Array 5*X]Nl\x{2022}u 5*X]Nl\x{2022}u Best regards, Daniel Struck --=20 Retrovirology Laboratory Luxembourg Centre Hospitalier de Luxembourg 4, rue E. Barbl=E9 L-1210 Luxembourg phone: +352-44116105 fax: +352-44116113 web: http://www.retrovirology.lu e-mail: struck.d@retrovirology.lu