Des plus decryption functions or classes that are compatible with PHP5.5 and 5.6

Source: Internet
Author: User
Tags deprecated
 key = $key;  if ($iv = = 0) {$this->iv = $key;  } else {$this->iv = $iv;//mcrypt_create_iv (Mcrypt_get_block_size (Mcrypt_des, MCRYPT_MODE_CBC), Mcrypt_dev_random  );  }} function Encrypt ($STR) {//encryption, return uppercase hexadecimal string $size = Mcrypt_get_block_size (Mcrypt_des, MCRYPT_MODE_CBC);  $str = $this->pkcs5pad ($str, $size); Return Strtoupper (Bin2Hex (MCRYPT_CBC (mcrypt_des, $this->key, $str, Mcrypt_encrypt, $this->iv)));  } function Decrypt ($STR) {//Decrypt $strBin = $this->hex2bin (strtolower ($STR));  $str = MCRYPT_CBC (mcrypt_des, $this->key, $strBin, Mcrypt_decrypt, $this->iv);  $str = $this->pkcs5unpad ($STR); return $str;  } function Hex2bin ($hexData) {$binData = "";  for ($i = 0; $i < strlen ($hexData); $i + = 2) {$binData. = Chr (Hexdec (substr ($hexData, $i, 2))); } return $binData;  } function Pkcs5pad ($text, $blocksize) {$pad = $blocksize-(strlen ($text)% $blocksize); Return $text. Str_repeat (Chr ($pad), $pad);} function Pkcs5unpad ($text) {$pad = Ord ($text {strlen ($text)-1});  if ($pad > strlen ($text)) return false;  if (strspn ($text, Chr ($pad), strlen ($text)-$pad)! = $pad) return false; Return substr ($text, 0,-1 * $pad); }} $my _encrypt = new DES (' Qwertyuiop '); Echo $my _encrypt->encrypt (' 1234567 ');

On the Internet to find all the wrong, the above affixed to this seems to be due to the PHP version of the problem test also has a variety of errors, do not know how to change.


Reply to discussion (solution)

Try this: http://www.cnblogs.com/wangchuang/archive/2012/04/23/2466002.html

Upstairs, the results of this test:

notice:uninitialized string Offset:6 in C:\web\project1\web\dec.php on line 148

notice:uninitialized string Offset:7 in C:\web\project1\web\dec.php on line 148

notice:uninitialized string Offset:6 in C:\web\project1\web\dec.php on line 148

notice:uninitialized string Offset:7 in C:\web\project1\web\dec.php on line 148
mdn2iafg6imabkvbi2l+ka==
Hello levenphp notice:uninitialized string offset:6 in C:\web\project1\web\dec.php on line 148 php notice:uninitialized String Offset:7 in C:\web\project1\web\dec.php-148 php notice:uninitialized string offset:6 in C:\web\project1 \web\dec.php on line 148 php notice:uninitialized string offset:7 in C:\web\project1\web\dec.php on line 148

function Encrypt ($STR, $key)  {      $block = mcrypt_get_block_size (' des ', ' ECB ');      $pad = $block-(strlen ($STR)% $block);      $str. = Str_repeat (Chr ($pad), $pad);      Return Mcrypt_encrypt (Mcrypt_des, $key, $str, MCRYPT_MODE_ECB);} function Decrypt ($str, $key)  {        $str = Mcrypt_decrypt (Mcrypt_des, $key, $str, MCRYPT_MODE_ECB);      $block = Mcrypt_get_block_size (' des ', ' ECB ');      $pad = Ord ($str [($len = strlen ($STR))-1]);      Return substr ($str, 0, strlen ($str)-$pad);  }  
php5.6.3 through
is said to be Java-compatible

You have deprecated:function MCRYPT_CBC () is Deprecated
It's obviously not going to work.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.