home *** CD-ROM | disk | FTP | other *** search
- <?php
- /*
- Copyright Intermesh 2003
- Author: Merijn Schering <mschering@intermesh.nl>
- Version: 1.0 Release date: 08 July 2003
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2 of the License, or (at your
- option) any later version.
- */
- class GO_CRYPTO extends db
- {
- var $time="";
- var $cryptokey;
- var $varcryptokey;
-
- function GO_CRYPTO(){
- global $GO_CONFIG;
- $this->db();
- $this->time="1073437878";
- $this->cryptokey='secret';
- $this->varcryptokey='secret';
- }
-
- function set_cryptokey(){
- $this->cryptokey=$_SESSION['GO_SESSION']['password'];
- return $this->cryptokey;
- }
-
- function bytexor($a,$b)
- {
- $c="";
- for($i=0;$i<strlen($a);$i++) {
- $a{$i}= isset($a{$i}) ? $a{$i} : null;
- $b{$i}= isset($b{$i}) ? $b{$i} : null;
- $c.=$a{$i}^$b{$i};
- }
- return($c);
- }
-
- function binmd5($val)
- {
- return(pack("H*",md5($val)));
- }
-
- function decrypt_md5($msg,$heslo,$time)
- {
- $key=$heslo.$time;$sifra="";
- $key1=$this->binmd5($key);
- while($msg) {
- $m=substr($msg,0,16);
- $msg=substr($msg,16);
- $sifra.=$m=$this->bytexor($m,$key1);
- $key1=$this->binmd5($key.$key1.$m);
- }
- return($sifra);
- }
-
- function crypt_md5($msg,$heslo,$time)
- {
- $key=$heslo.$time;$sifra="";
- $key1=$this->binmd5($key);
- while($msg) {
- $m=substr($msg,0,16);
- $msg=substr($msg,16);
- $sifra.=$this->bytexor($m,$key1);
- $key1=$this->binmd5($key.$key1.$m);
- }
- return($sifra);
- }
-
-
- function encrypt($text,$cryptokey=null){
- $this->set_cryptokey();
- if ($cryptokey==null) {$cryptokey=$this->cryptokey;}
- #echo "encrypting with passphrase: $cryptokey!!!<br>";
- $key="12345678";
- $base64="base64_encode";
- $url="urlencode";
- $fce="\$this->crypt_md5";
- return $url($base64($this->crypt_md5($text,$cryptokey,$this->time)));
- }
-
- function decrypt($text,$cryptokey=null){
- $this->set_cryptokey();
- if ($cryptokey==null) {$cryptokey=$this->cryptokey;}
- #echo "decrypting with passphrase: $cryptokey!!!<br>";
- $key="12345678";
- $fce="\$this->decrypt_md5";
- $base64="base64_decode";
- $url="urldecode";
- return $this->decrypt_md5($base64($url($text)),$cryptokey,$this->time);
- }
-
-
-
- function re_encrypt_email($user_id,$old_password,$password){
- $sql_accounts="select id,password from emAccounts where user_id='$user_id'";
- $this->query($sql_accounts);
- $that=new db();
- while($this->next_record()){
- $old_email_encrypted_password=$this->f('password');
- $old_email_password=$this->decrypt($old_email_encrypted_password,$old_password);
- $email_password=$this->encrypt($old_email_password,$password);
- $id=$this->f('id');
- $sql="update emAccounts set password='$email_password' where user_id='$user_id' and id='$id'";
- $that->query($sql);
- }
-
-
- }
- }
-