Below is MD5-based block cypher ( MDC-like ), which works in 128bit CFB mode. It is very useful to encrypt secret data before transfer it over the network.
<?php
/**********************************************
**
** MD5 block cypher
**
** Author..: leapinglangoor [ leapinglangoor@yahoo.co.in ]
** Date....: 30th Apr 2005
** version.: v1.00
**
** Desc....: Below is MD5-based block cypher ( MDC-like ),
** which works in 128bit CFB mode. It is very useful to
** encrypt secret data before transfer it over the network.
**
** $iv_len - initialization vector's length.
** 0 <= $iv_len <= 512
**
************************************************/
function get_rnd_iv ( $iv_len )
{
$iv = '' ;
while ( $iv_len -- > 0 )
{
$iv .= chr ( mt_rand ( ) & 0xff );
}
return $iv ;
}
function md5_encrypt ( $plain_text , $password , $iv_len = 16 )
{
$plain_text .= "\x13" ;
$n = strlen ( $plain_text );
if ( $n % 16 )
{
$plain_text .= str_repeat ( "\0" , 16 - ( $n % 16 ) );
}
$i = 0 ;
$enc_text = get_rnd_iv ( $iv_len );
$iv = substr ( $password ^ $enc_text , 0 , 512 );
while ( $i < $n )
{
$block = substr ( $plain_text , $i , 16 ) ^ pack ( 'H*' , md5 ( $iv ) );
$enc_text .= $block ;
$iv = substr ( $block . $iv , 0 , 512 ) ^ $password ;
$i += 16 ;
}
return base64_encode ( $enc_text );
}
function md5_decrypt ( $enc_text , $password , $iv_len = 16 )
{
$enc_text = base64_decode ( $enc_text );
$n = strlen ( $enc_text );
$i = $iv_len ;
$plain_text = '' ;
$iv = substr ( $password ^ substr ( $enc_text , 0 , $iv_len ), 0 , 512 );
while ( $i < $n )
{
$block = substr ( $enc_text , $i , 16 );
$plain_text .= $block ^ pack ( 'H*' , md5 ( $iv ) );
$iv = substr ( $block . $iv , 0 , 512 ) ^ $password ;
$i += 16 ;
}
return preg_replace ( '/\\x13\\x00*$/' , '' , $plain_text );
}
?>
example.php:
<?php
include( 'md5.php' );
$plain_text = 'very secret string' ;
$password = 'very secret password' ;
echo "plain text is: [ ${ plain_text } ]<br />\n" ;
echo "password is: [ ${ password } ]<br />\n" ;
$enc_text = md5_encrypt ( $plain_text , $password );
echo "encrypted text is: [ ${ enc_text } ]<br />\n" ;
$plain_text2 = md5_decrypt ( $enc_text , $password );
echo "decrypted text is: [ ${ plain_text2 } ]<br />\n" ;
?>
base64 with encryption - encode and decode sessions Categories : PHP , PHP Classes , Encryption , Sessions Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP , PHP , HTML , PDF , Excel Scramble Eggs - php class to scramble/encode Categories : PHP , PHP Classes , Security , Encryption A PHP function to encrypt and decrypt a number or string or a combination of the two. Categories : PHP , Encryption , Security Encrypt/Decrypt string with a given key by using mcrypt module of PHP (suitable to store encrypted data into any type of databases). Categories : PHP , Encryption PHP Cookies - Simple cookie write/read methods that allow basic encryption Categories : PHP , Cookies , Security , Encryption PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character. Categories : PHP , Algorithms , Security , Authentication , Encryption Blueshoes PHP Application Framework Categories : PHP , Frameworks , PHP Classes Parses HTTP_USER_AGENT so that you can customize your site to different browsers Categories : HTML , PHP , Complete Programs Implementing a Members ONLY area Categories : PHP , MySQL , Databases , Authentication GoTemplate Categories : PHP , Complete Programs , Templates Simple PHP function benchmark Categories : PHP , Testing Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but
effective. Categories : PHP , PHP Classes , HTML , HTML and PHP Finds files on your site, uses UNIX find command. Categories : Complete Programs , Filesystem , PHP EasySQL - connect to MySQL with just 1 php file Categories : PHP , To MySQL , Databases