DB_Sqlite_Tools

AdvancedSearch | AreaMap ]

Search:

  Welcome to DB_SqLite_Tools   Docs   DBC Encryption and Decryption   Install DB_Sqlite_Tools  
   

Username:

Password:


Areas In
This Wiki

Main

DBC Encryption and Decryption

Here is a short but self explanatory example on how to use DB_Sqlite_Tools to insert and retrieve encrypted data to/from your sqlite database.

MySQL? offers an in build encryption mechanism with the AES (aka Rijndael) and DES encryption algorithms which is certainly important to many.

More sophisticated databases like Oracle go even further supporting the Triple DES3 standard.

As it was discussed on several mailing lists, Sqlite might not always offer the same degree of security of a database engine.
For this very reason it might be advisable to encrypt sensible data.

Now, via DB_SQLite_Tools you can retrieve (decrypting data on the fly) and insert (encrypting on the fly) data securely from and to your Sqlite database.

This functionaliy uses the ARCFOUR Encryption Algorithm. This encryption function is bundled in the package so you are not required to install anything else nor to compile PHP with mcrypt support.

note: In a real implementation you won't store the encryption key on the file
but you will ask the user via a form and pass the value of $_REQUEST['yourfieldname'] to the script.

you can see the live demo here
and the encrypted database here


<?php

// Quick DB_Sqlite_Tools DBC Database encryption/description functionality tutorial
// inserting and retriving crypted data 
    
require_once 'DB/Sqlite/Tools.php';

    $db = new DB_Sqlite_Tools_DBC;
    $db->debug = true;
    $db->liteConnect ('clown.sqlite');
    $db->key = 'gurugeek';

    $sql = "SELECT * FROM matrix ORDER BY RANDOM();"; // query used on liteAutoFetch
    $sql2 = "SELECT * FROM matrix"; // query used on liteAll
    $db->liteAutoFetch($sql,true); // fetching and decrypting 
    echo '<BR> fetching a single result, is decrypted on the fly <BR>';
    echo $db->result->clown."<BR>";
    echo $db->result->circus."<BR>";
    
    $db->liteAll ($sql2,true); // fetching all the results and decrypting

    foreach ($db->result as $rid => $row) { 
             print $rid."<br>\n"; 
             print $row->clown;
             print $row->circus; 
         }
        
    // updating record 8
    $fields = array ('clown','circus');
    $values = array ('2387123128324903420983','mastercard');
    $db->liteAutoExec ('matrix',$fields,$values,DB_Sqlite_Tools_DBC::DB_AUTOQUERY_UPDATE, true, 'id=8');

    //inserting a new record 
    $fields = array ('clown','circus');
    $values = array (date ("U"),'amex');
    $db->liteAutoExec ('matrix',$fields,$values,DB_Sqlite_Tools_DBC::DB_AUTOQUERY_INSERT);

?>
Main:DBcTutorial (gurugeek)
Wed, 29 Sep 2004, 16:27
[ Links | Source | History | RSS ]

This site powered by Yawiki 0.17.2 alpha.



Commenting disabled for the viagra m*****rs