note 80808 added to ref.mcrypt

From: Date: Fri, 01 Feb 2008 09:18:34 +0000
Subject: note 80808 added to ref.mcrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-135694@lists.php.net to get a copy of this message
The Pear class Crypt/Blowfish.php will use the mcrypt module if available but the mcrypt module is not required. Some very easy Pear and example pseudocode to protect your data by encrypting your databases with a one-way hash and blowfish symmetric encryption. http://en.wikibooks.org/wiki/Cryptography/Database_protection Using a one-way hash and blowfish symmetric encryption. 1. Insert a record of John Doe in an encrypted database. 2. Get the encrypted record of user John Doe and decrypt the data. 1. Insert a record of John Doe in an encrypted database. <?php require_once("Crypt/Blowfish.php"); // a Pear class $aRecord['email'] = "johndoe@anisp.localhost"; // The Primary key $aRecord['name'] = "John Doe"; $aRecord['creditnr'] = "0192733652342" ; // crypt - one-way encryption $cipher_key = crypt( $aRecord['email'] , "AN_SECRET_COMPANY_SALT"); $bf = new Crypt_Blowfish('ecb'); $bf->setKey( $cipher_key ); // crypt_blowfish symmetric encryption to encrypt the data $aRecord['email'] = $bf->encrypt( $aRecord['email'] ); $aRecord['name'] = $bf->encrypt( $aRecord['name'] ); $aRecord['creditnr'] = $bf->encrypt( $aRecord['creditnr'] ); $result = sqlInsert( $aRecord ) ; ?> 2. Get the encrypted record of user John Doe and decrypt the data. <?php require_once("Crypt/Blowfish.php"); // a Pear class $primary_key = "johndoe@anisp.localhost"; // crypt - one-way encryption $cipher_key = crypt( $primary_key , "AN_SECRET_COMPANY_SALT"); $bf = new Crypt_Blowfish('ecb'); $bf->setKey( $cipher_key ); // crypt_blowfish symmetric encryption to ecrypt the primary key for a sql select $select_key = $bf->encrypt( $primary_key ) ; $aRecord = sqlSelectWithPKEY( $select_key ); // crypt_blowfish symmetric encryption to decrypt the data $aRecord['email'] = $bf->decrypt( $aRecord['email'] ); $aRecord['name'] = $bf->decrypt( $aRecord['name'] ); $aRecord['creditnr'] = $bf->decrypt( $aRecord['creditnr'] ); ?> Thanks for reading this. ---- Server IP: 89.248.170.58 Probable Submitter: 88.211.161.88 ---- Manual Page -- http://www.php.net/manual/en/ref.mcrypt.php Edit -- https://master.php.net/note/edit/80808 Del: integrated -- https://master.php.net/note/delete/80808/integrated Del: useless -- https://master.php.net/note/delete/80808/useless Del: bad code -- https://master.php.net/note/delete/80808/bad+code Del: spam -- https://master.php.net/note/delete/80808/spam Del: non-english -- https://master.php.net/note/delete/80808/non-english Del: in docs -- https://master.php.net/note/delete/80808/in+docs Del: other reasons-- https://master.php.net/note/delete/80808 Reject -- https://master.php.net/note/reject/80808 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135694) next »