Пример #1
0
 public function create()
 {
     $algo = 'twofish';
     $mode = 'cbc';
     $iv = mcrypt_create_iv(mcrypt_get_iv_size($algo, $mode));
     $hash = 'sha256';
     $password = $this->password;
     $message = $this->message;
     $key = hash($hash, $password, false);
     $td = mcrypt_module_open($algo, '', $mode, '');
     mcrypt_generic_init($td, $password, $iv);
     $encmsg = mcrypt_generic($td, $message);
     mcrypt_generic_deinit($td);
     mcrypt_module_close($td);
     $spastie = new Spastie();
     $spastie->key = $key;
     $spastie->msg = base64_encode($encmsg);
     $spastie->iv = bin2hex($iv);
     return $spastie->save();
 }
Пример #2
0
 public function fetch()
 {
     $algo = 'twofish';
     $mode = 'cbc';
     $hash = 'sha256';
     $password = $this->password;
     $key = hash($hash, $password, false);
     $spastie = Spastie::find()->where(['key' => $key])->one();
     if ($spastie) {
         $td = mcrypt_module_open($algo, '', $mode, '');
         $iv = hex2bin($spastie->iv);
         mcrypt_generic_init($td, $password, $iv);
         $contents = mdecrypt_generic($td, base64_decode($spastie->msg));
         mcrypt_generic_deinit($td);
         mcrypt_module_close($td);
         return [true, $contents];
     } else {
         return [false, ''];
     }
 }