以DES-CBC加密方式为例:
<?php class DesUtil { /** * Des 加密 * * @param $str * @param $secretKey * @param string $iv * @return string */ public static function encrypt($str, $secretKey, $iv = '') { return base64_encode(openssl_encrypt($str, 'des-cbc', $secretKey, OPENSSL_RAW_DATA, $iv)); } /** * Des 解密 * * @param $str * @param $secretKey * @param string $iv * @return string */ public static function decrypt($str, $secretKey, $iv = '') { return openssl_decrypt(base64_decode($str), 'des-cbc', $secretKey, OPENSSL_RAW_DATA, $iv); } }
原创文章,作者:YGAZC,如若转载,请注明出处:http://www.wangzhanshi.com/n/16419.html