PHP functions for string encryption and decryption. Encryption and decryption is a common requirement in a system. PHP websites often use encryption and decryption. The following describes how to use encryption and decryption functions to encrypt and decrypt data in a system. PHP websites often use encryption and decryption. The following describes a useful encryption and decryption function, which will be used in the future.
'; Echo' decryption :'. encrypt ($ token, 'D', 'bkjia '); /*************************************** * ***************************** function name: encrypt function: encryption and decryption string usage: Encryption: encrypt ('str', 'e', 'bkjia '); decryption: encrypt ('encrypted string ', 'D', 'bkjia '); parameter description: $ string: string to be encrypted and decrypted $ operation: whether to encrypt or decrypt: E: encrypted D: decrypt $ key: encrypted Key (key ); **************************************** * ***************************/function encrypt ($ string, $ operation, $ key =' ') {$ Key = md5 ($ key); $ key_length = strlen ($ key); $ string = $ operation = 'D '? Base64_decode ($ string): substr (md5 ($ string. $ key), 0, 8 ). $ string; $ string_length = strlen ($ string); $ rndkey = $ box = array (); $ result = ''; for ($ I = 0; $ I <= 255; $ I ++) {$ rndkey [$ I] = ord ($ key [$ I % $ key_length]); $ box [$ I] = $ I;} for ($ j = $ I = 0; $ I <256; $ I ++) {$ j = ($ j + $ box [$ I] + $ rndkey [$ I]) % 256; $ tmp = $ box [$ I]; $ box [$ I] = $ box [$ j]; $ box [$ j] = $ tmp;} for ($ a = $ j = $ I = 0; $ I <$ string_length; $ I ++) {$ a = ($ a + 1) % 256; $ j = ($ j + $ box [$ a]) % 256; $ tmp = $ Box [$ a]; $ box [$ a] = $ box [$ j]; $ box [$ j] = $ tmp; $ result. = chr (ord ($ string [$ I]) ^ ($ box [($ box [$ a] + $ box [$ j]) % 256]);} if ($ operation = 'd') {if (substr ($ result,) = substr (md5 (substr ($ result, 8 ). $ key),) {return substr ($ result, 8) ;}else {return '';}} else {return str_replace ('= ','', base64_encode ($ result) ;}}?>
Bytes. The following describes a relatively useful encryption and decryption letter...