PHP string encryption and decryption function. Sometimes we don't want to see a webpage address. the simple method is to encrypt it into a string of characters. the function is as follows: functionencrypt ($ key, $ plain_text) {$ plain_textt sometimes we don't want it to be seen by a webpage address. the simple method is to encrypt it into a string of characters. the function is as follows:
Function encrypt ($ key, $ plain_text ){
$ Plain_text = trim ($ plain_text );
$ Iv = substr (md5 ($ key), 0, mcrypt_get_iv_size (MCRYPT_CAST_256, MCRYPT_MODE_CFB ));
$ C_t = mcrypt_cfb (MCRYPT_CAST_256, $ key, $ plain_text, MCRYPT_ENCRYPT, $ iv );
Return trim (chop (base64_encode ($ c_t )));
}
$ Key can be set as needed, and $ plain_text is the string to be encrypted. Corresponding decryption function:
Function decrypt ($ key, $ c_t ){
$ C_t = trim (chop (base64_decode ($ c_t )));
$ Iv = substr (md5 ($ key), 0, mcrypt_get_iv_size (MCRYPT_CAST_256, MCRYPT_MODE_CFB ));
$ P_t = mcrypt_cfb (MCRYPT_CAST_256, $ key, $ c_t, MCRYPT_DECRYPT, $ iv );
Return trim (chop ($ p_t ));
}
$ Plain_text is the string to be decrypted;
Note: If you use a url to pass encrypted strings as parameters, use the URLEncode () function to encrypt them. Otherwise, use decrypt ($ key, $ c_t) the parameters obtained by function decryption cannot obtain the original string.
Encryption function encrypt ($ key, $ plain_text) {$ plain_text = t...