PHP encryption and decryption functions

Source: Internet
Author: User
This article mainly introduces the function of PHP encryption and decryption, which implements the function of encrypting some variable values. if you are interested, please refer to a function of PHP encryption and decryption, this function encrypts some variable values.
The encryption code is as follows:

/** Function: encrypt strings * parameter 1: content to be encrypted * parameter 2: key */function passport_encrypt ($ str, $ key) {// encryption function srand (double) microtime () * 1000000); $ encrypt_key = md5 (rand (0, 32000); $ ctr = 0; $ tmp = ''; for ($ I = 0; $ I
 
  

The decryption code is as follows:

/** Function: decrypts strings * parameter 1: ciphertext to be decrypted * parameter 2: key */function passport_decrypt ($ str, $ key) {// decryption function $ str = passport_key (base64_decode ($ str), $ key); $ tmp = ''; for ($ I = 0; $ I
   
    

Auxiliary functions:

/** Auxiliary function */function passport_key ($ str, $ encrypt_key) {$ encrypt_key = md5 ($ encrypt_key); $ ctr = 0; $ tmp = ''; for ($ I = 0; $ I
     
      

The usage is as follows:

$ Str = 'Author: Yu Haomiao; Tel: 13611972365; email: 123cvbz@163.com '; $ key = 'hacker'; $ encrypt = passport_encrypt ($ str, $ key ); $ decrypt = passport_decrypt ($ encrypt, $ key); echo 'original: ', $ str."
"; Echo 'ciphertext: ', $ encrypt ."
"; Echo 'Translation: ', $ decrypt ."
";

The above is the php encryption and decryption function shared for you. I hope you will like it and use it for your own learning.

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.