PHP Simple implementation des encryption and decryption method _php skills

Source: Internet
Author: User
Tags strlen

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.

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.