欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php基于mcrypt_encrypt和mcrypt_decrypt實(shí)現(xiàn)字符串加密解密的方法

 更新時(shí)間:2016年07月12日 10:25:04   作者:lwx2615  
這篇文章主要介紹了php基于mcrypt_encrypt和mcrypt_decrypt實(shí)現(xiàn)字符串加密解密的方法,結(jié)合實(shí)例形式分析了mcrypt_encrypt和mcrypt_decrypt函數(shù)進(jìn)行加密、解密的相關(guān)使用技巧,需要的朋友可以參考下

本文實(shí)例講述了php基于mcrypt_encrypt和mcrypt_decrypt實(shí)現(xiàn)字符串加密解密的方法。分享給大家供大家參考,具體如下:

由于出于安全考慮,參數(shù)傳遞的時(shí)候需要進(jìn)行加密和解密,一個(gè)比較簡(jiǎn)單的方法是直接使用php中的函數(shù)mcrypt_encrypt、mcrypt_decrypt,一個(gè)加密,一個(gè)解密,但是問(wèn)題又出現(xiàn)了,這個(gè)加密過(guò)程中會(huì)產(chǎn)生一些使url混亂的符號(hào),于是在加密后對(duì)加密字符再進(jìn)行一次處理,然后多了一一次解析:

$key = "miyao";//密鑰
$string="jiami"http://需要加密的字符
//自帶的加密函數(shù)
$crypttext = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
$encrypted =trim($this->safe_b64encode($crypttext));//對(duì)特殊字符進(jìn)行處理
$key="miyao"
$crypttexttb=safe_b64decode($encrypted)//對(duì)特殊字符解析
$decryptedtb = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($crypttexttb), MCRYPT_MODE_CBC, md5(md5($key))), "\0")//解密函數(shù)
//處理特殊字符
public function safe_b64encode($string) {
    $data = base64_encode($string);
    $data = str_replace(array('+','/','='),array('-','_',''),$data);
    return $data;
}
//解析特殊字符
public function safe_b64decode($string) {
    $data = str_replace(array('-','_'),array('+','/'),$string);
    $mod4 = strlen($data) % 4;
    if ($mod4) {
      $data .= substr('====', $mod4);
    }
    return base64_decode($data);
}

PS:關(guān)于加密解密感興趣的朋友還可以參考本站在線工具:

密碼安全性在線檢測(cè):
http://tools.jb51.net/password/my_password_safe

高強(qiáng)度密碼生成器:
http://tools.jb51.net/password/CreateStrongPassword

MD5在線加密工具:
http://tools.jb51.net/password/CreateMD5Password

迅雷、快車、旋風(fēng)URL加密/解密工具:
http://tools.jb51.net/password/urlrethunder

在線散列/哈希算法加密工具:
http://tools.jb51.net/password/hash_encrypt

更多關(guān)于PHP相關(guān)內(nèi)容可查看本站專題:《php加密方法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門(mén)教程》、《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論