Thread: Creating a real user database / Log-in.

View Single Post

  #5 (permalink)  

Old 05-15-2005, 11:38 AM

Here are two functions i wrote to encrypt and decrypt some text. It takes a global key to encrypt it, which means that the passwords cant be unencrypted unless the key is thrown into the function.

PHP Code:
//md5 encryption
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_text0512);
   while (
$i $n) {
       
$block substr($plain_text$i16) ^ pack('H*'md5($iv));
       
$enc_text .= $block;
       
$iv substr($block $iv0512) ^ $password;
       
$i += 16;
   }
   return 
base64_encode($enc_text);
}
//md5 decryption
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_text0$iv_len), 0512);
   while (
$i $n) {
       
$block substr($enc_text$i16);
       
$plain_text .= $block pack('H*'md5($iv));
       
$iv substr($block $iv0512) ^ $password;
       
$i += 16;
   }
   return 
preg_replace('/\\x13\\x00*$/'''$plain_text);

To use it you would do somethign like this:

PHP Code:
$encrypt_key 'globalencryption';
$string md5_encrypt('password',$encrypt_key); 
__________________
Audi Videos | MySpace Layouts | About Me | Kid Sniffles
[ reply ]
missionsix

missionsix is offline http://patandrew.com/

missionsix's Avatar

Join Date: Feb 2004

Location: under you.

Posts: 4,876

Send a message via AIM to missionsix Send a message via MSN to missionsix