php help

10 posts Page 1 of 1
Contributors
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

php help
Shim
hello guys i am not in to php actually so i need someone to make this class work
Code: Select all
<?php
/*
 * This class encapsulates Blowfish encryption and decryption.
 */
class Encrypter{
   protected $key;
   protected $iv;
    
   function __construct($iv=null, $key=null){
      $this->iv = $iv;
      $this->key = $key;
   }
    
   /**
    * Encrypts data
    * Returns binary data.    
    */      
   function encrypt($data){
      $len = strlen($data);
      $enc = mcrypt_encrypt( MCRYPT_BLOWFISH, $this->key, $data, MCRYPT_MODE_CBC, $this->iv );
      return $enc;
   }
    
   /**
    * Encrypts data and convert to hex. 
    * Ideal for storing as text.   
    */      
   function encryptToHex($data){
      return $this->bin2hex($this->encrypt($data));
   }
    
   /**
    * Takes hex input, convert from hex to binary then decrypt.
    */      
   function decryptFromHex($data){
      //echo "hex \"$data\"\n";
      return $this->decrypt($this->hex2bin($data));
   }
 
   /**
    *
    */      
   function decrypt($data){
      $decode = mcrypt_decrypt( MCRYPT_BLOWFISH, $this->key, $data, MCRYPT_MODE_CBC, $this->iv );
      //echo "decode \"$decode\"\n";
      $realdata = rtrim($decode, "\0");
       
      //echo sprintf("[%s]\n", $realdata);
      return $realdata;
   }
    
   /**
    * Convert from binary to hex
    */      
   function bin2hex($s){
      return bin2hex($s);
   }
    
   /**
    * Convert from hex to binary
    */      
   function hex2bin($s){
      return pack("H*", $s);   
   }
 
   /**
    * loads key and iv from a file.
    * Key is on line 1 in hex.
    * IV is on line 2 in hex.        
    */      
   function loadKeysFromFile($filename){
      return $this->loadKeysFromString(file_get_contents($filename));
   }
    
   /**
    * String is the key and the iv separates by a newline.
    * Use this when storing the key in a file.
    * Line 1 would be the key, line 2 is the iv.        
    */      
   function loadKeysFromString($string){
      $keys = explode("\n", $string);
      $key = $keys[0];
      $iv = pack("H*", $keys[1]);
      $this->key = $key;
      $this->iv = $iv;
      return array($key, $iv);
   }
    
   function showKeys(){
      return sprintf("%s %s", $this->key, $this->bin2hex($this->iv));
   }
}
send me the whole file please
Find my programs on Softpedia
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: php help
smashapps
The syntax is correct if you're using an updated version of PHP. If you're using PHP 4 there are errors. What version of PHP are you using?
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: php help
Shim
smashapps wrote:
The syntax is correct if you're using an updated version of PHP. If you're using PHP 4 there are errors. What version of PHP are you using?
my php version : 5.4.7

i know the syntax is correct all i want is i want someone to make the class work i mean i want to see the action .
Find my programs on Softpedia
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: php help
smashapps
Ohhh alright I'll try and get it working soon. I have to work tonight so I might be back on in about 4 hours.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Re: php help
benji_19994
May i ask what error your getting how can we help if you don't tell us
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: php help
smashapps
I'm writing up a form I will give you the full code when I get back.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: php help
Shim
smashapps wrote:
Ohhh alright I'll try and get it working soon. I have to work tonight so I might be back on in about 4 hours.
thanks for starting the work cooll;
Find my programs on Softpedia
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Re: php help
benji_19994
Do you know oop in php?
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: php help
Shim
benji_19994 wrote:
Do you know oop in php?
i don't have any experience in php :(
Find my programs on Softpedia
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Re: php help
benji_19994
Found this on the internet
You do not have the required permissions to view the files attached to this post.
10 posts Page 1 of 1
Return to “Help & Support”