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.