php aes加密

來源:互聯網
上載者:User

標籤:個數   substr   init   bind   mcr   div   cti   ip地址   lld   

    private $iv = ‘lua123456789qwer‘; #隨便填寫16個數    private $key = ‘123456789asdfghjkl$$$$$‘; #隨便寫多少    //加密    function encryptlua($str) {      //$key = $this->hex2bin($key);          $iv = $this->iv;      $td = mcrypt_module_open(‘rijndael-128‘, ‘‘, ‘cbc‘, $iv);      mcrypt_generic_init($td, $this->key, $iv);      $encrypted = mcrypt_generic($td, $str);      mcrypt_generic_deinit($td);      mcrypt_module_close($td);      return bin2hex($encrypted);    }    //解密    function decryptlua($str) {      //$key = $this->hex2bin($key);      $str = $this->hex2bin($str);      $iv = $this->iv;      $td = mcrypt_module_open(‘rijndael-128‘, ‘‘, ‘cbc‘, $iv);      mcrypt_generic_init($td, $this->key, $iv);      $decrypted = mdecrypt_generic($td, $str);      mcrypt_generic_deinit($td);      mcrypt_module_close($td);      return utf8_encode(trim($decrypted));    }    protected function hex2bin($hexdata) {      $bindata = ‘‘;      for ($i = 0; $i < strlen($hexdata); $i += 2) {            $bindata .= chr(hexdec(substr($hexdata, $i, 2)));      }      return $bindata;    }

demo

 

public function actionIndex()    {        $c=json_encode(‘{"state":"failed","message":"當前IP地址[119.90.13.163]:24小時次數[2],30天次數[2]","data":{"ip":"119.90.13.163","area":"中國北京北京","oneday":2,"allday":2}}‘);        $a=$this->encryptlua($c);        $b=json_decode($this->decryptlua($a));        echo $a;        echo ‘<br>‘;        echo $b;

 

php aes加密

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.