<?php
public $key = "key";
public $string;
public $mode = MCRYPT_MODE_CFB;
public $algorythm = MCRYPT_BLOWFISH;
public $iv_size;
public $iv;
public function __construct($string){
$this->string = $string;
$this->iv_size = mcrypt_get_iv_size($this->algorythm,$this->mode);
$this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
}
public function decrypt(){
echo mcrypt_decrypt
($this->algorythm, $this->key, $this->string, $this->mode, $this->iv); }
public function encrypt(){
echo mcrypt_encrypt
($this->algorythm, $this->key, $this->string, $this->mode, $this->iv); }
}
?>
nie wiem o co chodzi, jak wywoluje encrypt() a pozniej decrypt() tego co zakodowalem to niestety dostaje co innego niż podałe, może ktoś mi pomóc?
Może się kiedyś komuś przyda to co zlepiłem z manuala php:
<?php
const key = "2@&#BDW_=+kjhs89y9h9";
public static function decrypt
($string){ $td = mcrypt_module_open('des', '','cfb', '');
$key = substr(self::key, 0
, mcrypt_enc_get_key_size
($td)); $iv_size = mcrypt_enc_get_iv_size($td);
for($i=0;$i<count($rare);$i++) $decrypted.=chr($rare[$i]);
$string = $decrypted;
$iv = substr($string,0
,$iv_size); $string = substr($string,$iv_size); if (mcrypt_generic_init($td, $key, $iv) != -1) {
$decrypted = mdecrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $decrypted;
}
}
public static function encrypt
($string){ $td = mcrypt_module_open('des', '','cfb', '');
$key = substr(self::key, 0
, mcrypt_enc_get_key_size
($td)); $iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
if (mcrypt_generic_init($td, $key, $iv) != -1) {
$c_t = mcrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$c_t = $iv.$c_t;
for($i=0;$i<strlen($c_t);$i++) $encrypted[$i]=ord($c_t[$i]);
$encrypted = implode("&",$encrypted);
return $encrypted;
}
}
}
?>
proste w użyciu:
crypt::decrypt("wczesniej zakodowany clasa crypt string");
crypt::encrypt("string do zakodowania");
A może ktoś ma pomysł jak to usprawnić?
Ten post edytował deirathe 4.07.2007, 20:13:37