1. <?php
  2. class crypt{
  3.  
  4. public $key = "key";
  5. public $string;
  6. public $mode = MCRYPT_MODE_CFB;
  7. public $algorythm = MCRYPT_BLOWFISH;
  8. public $iv_size;
  9. public $iv;
  10.  
  11. public function __construct($string){
  12. $this->string = $string;
  13. $this->iv_size = mcrypt_get_iv_size($this->algorythm,$this->mode);
  14. $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
  15. }
  16. public function decrypt(){
  17. echo mcrypt_decrypt($this->algorythm, $this->key, $this->string, $this->mode, $this->iv);
  18. }
  19. public function encrypt(){
  20. echo mcrypt_encrypt($this->algorythm, $this->key, $this->string, $this->mode, $this->iv);
  21. }
  22.  
  23. }
  24. ?>


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:
  1. <?php
  2. class crypt{
  3. const key = "2@&#BDW_=+kjhs89y9h9";
  4.  
  5. public static function decrypt($string){
  6. $td = mcrypt_module_open('des', '','cfb', '');
  7. $key = substr(self::key, 0, mcrypt_enc_get_key_size($td));
  8. $iv_size = mcrypt_enc_get_iv_size($td);
  9. srand((double) microtime() * 1000000); 
  10.  
  11. $rare = explode("&",$string);
  12. for($i=0;$i<count($rare);$i++) $decrypted.=chr($rare[$i]);
  13. $string = $decrypted;
  14. $iv = substr($string,0,$iv_size);
  15. $string = substr($string,$iv_size);
  16. if (mcrypt_generic_init($td, $key, $iv) != -1) {
  17. $decrypted = mdecrypt_generic($td, $string);
  18. mcrypt_generic_deinit($td);
  19. mcrypt_module_close($td);
  20. return $decrypted;
  21. }
  22. }
  23. public static function encrypt($string){
  24. $td = mcrypt_module_open('des', '','cfb', '');
  25. $key = substr(self::key, 0, mcrypt_enc_get_key_size($td));
  26. $iv_size = mcrypt_enc_get_iv_size($td);
  27. srand((double) microtime() * 1000000); 
  28. $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  29.  
  30. if (mcrypt_generic_init($td, $key, $iv) != -1) {
  31.  
  32. $c_t = mcrypt_generic($td, $string);
  33. mcrypt_generic_deinit($td);
  34. mcrypt_module_close($td);
  35. $c_t = $iv.$c_t;
  36.  
  37. for($i=0;$i<strlen($c_t);$i++) $encrypted[$i]=ord($c_t[$i]);
  38. $encrypted = implode("&",$encrypted);
  39.  
  40. return $encrypted;
  41. }
  42. }
  43.  
  44. }
  45. ?>

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ć?