php help
10 posts
Page 1 of 1
hello guys i am not in to php actually so i need someone to make this class work
Code: Select all
send me the whole file please<?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));
}
}
Find my programs on Softpedia
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!
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
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!
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!
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
benji_19994 wrote:Do you know oop in php?i don't have any experience in php :(
Find my programs on Softpedia
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
Copyright Information
Copyright © Codenstuff.com 2020 - 2023