PHP加密和解密函数

2015-07-18 10:42:59来源:作者:王道中强流人点击

php/** * Returns an encrypted string */function encrypt($pure_string, $encryption_key) {$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);$encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, $pure_string, MCRYPT_MODE_ECB, $iv);return rawurlencode($encrypted_string);}/** * Returns decrypted original string */function decrypt($encrypted_string, $encryption_key) {$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);$decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $encryption_key, rawurldecode($encrypted_string), MCRYPT_MODE_ECB, $iv);return $decrypted_string;}

微信扫一扫

第七城市微信公众平台