This article illustrates the simple method of implementing DES encryption and decryption by PHP. Share to everyone for your reference, specific as follows:
DES encryption:
function Des_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);
}
Des decryption:
function Des_decrypt ($STR, $key) {
$str = Mcrypt_decrypt (Mcrypt_des, $key, $str, MCRYPT_MODE_ECB);
$len = strlen ($STR);
$block = Mcrypt_get_block_size (' des ', ' ECB ');
$pad = Ord ($str [$len-1]);
Return substr ($str, 0, $len-$pad);
PS: About encryption and decryption interested friends can also refer to the site online tools:
Password Security online detection:
Http://tools.jb51.net/password/my_password_safe
High Strength Password Generator:
Http://tools.jb51.net/password/CreateStrongPassword
MD5 Online Encryption Tool:
Http://tools.jb51.net/password/CreateMD5Password
Thunderbolt, Express, Cyclone URL encryption/decryption tool:
Http://tools.jb51.net/password/urlrethunder
Online hashing/hashing algorithm encryption tool:
Http://tools.jb51.net/password/hash_encrypt
More about PHP related content to view the site topics: "PHP Encryption Method Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP operation Office Document Skills Summary (including Word,excel, Access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.