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.