This article mainly introduces the PHP encryption and decryption function, which implements the encryption function for some variable values. If you are interested, refer to it.
This article mainly introduces the PHP encryption and decryption function, which implements the encryption function for some variable values. If you are interested, refer to it.
Share a function of PHP encryption and decryption, which implements encryption of 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 everyone. I hope you will like it and apply it to your own learning.