Reprint Please specify source: http://blog.csdn.net/l1028386804/article/details/46045127
PHP can use mcrypt_encrypt for DES encryption and decryption, but actually operation, you will find it with Java des encryption out of the string, a little different. Basically the first half of the paragraph, the second half is different. Find the PHP official website on this function of the document, someone replied, and gave the code. It is tested so that encryption and decryption are compatible with Java.
<?php 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);}? >
PHP--des plus decryption function compatible with Java (episode)