如果不用在Yii框架中,把代碼中Yii::app()->params['encryptKey'] 換成你對(duì)應(yīng)的默認(rèn)key就可以了。
類代碼:
<&#63;php/** * php AES加解密類 * 如果要與java共用,則密鑰 " /> xxx一区,国产毛片毛片毛片毛片毛片,黑丝一区

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

php寫的AES加密解密類分享

今天寫了一個(gè)php的AES加密類。適用于Yii的擴(kuò)展。
如果不用在Yii框架中,把代碼中Yii::app()->params['encryptKey'] 換成你對(duì)應(yīng)的默認(rèn)key就可以了。
類代碼:

<?php/** * php AES加解密類 * 如果要與Java共用,則密鑰長(zhǎng)度應(yīng)該為16位長(zhǎng)度 * 因?yàn)?a href=/itjie/Javajishu/ target=_blank class=infotextkey>Java只支持128位加密,所以php也用128位加密,可以與Java互轉(zhuǎn)。 * 同時(shí)AES的標(biāo)準(zhǔn)也是128位。只是RIJNDAEL算法可以支持128,192和256位加密。 * Java 要使用AES/CBC/NoPadding標(biāo)準(zhǔn)來(lái)加解密 *  * @author Terry * */class phpAes{	/**	 * This was AES-128 / CBC / NoPadding encrypted.	 * return base64_encode string	 * @author Terry	 * @param string $plaintext	 * @param string $key	 */	public static function AesEncrypt($plaintext,$key = null)	{		$plaintext = trim($plaintext);		if ($plaintext == '') return '';		if(!extension_loaded('mcrypt'))			throw new CException(Yii::t('yii','AesEncrypt requires php mcrypt extension to be loaded in order to use data encryption feature.'));		$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);		$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');		$key=self::substr($key===null ? Yii::app()->params['encryptKey'] : $key, 0, mcrypt_enc_get_key_size($module));		/* Create the IV and determine the keysize length, use MCRYPT_RAND		 * on Windows instead */		$iv = substr(md5($key),0,mcrypt_enc_get_iv_size($module));		/* Intialize encryption */		mcrypt_generic_init($module, $key, $iv);		/* Encrypt data */		$encrypted = mcrypt_generic($module, $plaintext);		/* Terminate encryption handler */		mcrypt_generic_deinit($module);		mcrypt_module_close($module);		return base64_encode($encrypted);	}	/**	 * This was AES-128 / CBC / NoPadding decrypted.	 * @author Terry	 * @param string $encrypted		base64_encode encrypted string	 * @param string $key	 * @throws CException	 * @return string	 */	public static function AesDecrypt($encrypted, $key = null)	{		if ($encrypted == '') return '';		if(!extension_loaded('mcrypt'))			throw new CException(Yii::t('yii','AesDecrypt requires php mcrypt extension to be loaded in order to use data encryption feature.'));		$ciphertext_dec = base64_decode($encrypted);		$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');		$key=self::substr($key===null ? Yii::app()->params['encryptKey'] : $key, 0, mcrypt_enc_get_key_size($module));		$iv = substr(md5($key),0,mcrypt_enc_get_iv_size($module));		/* Initialize encryption module for decryption */		mcrypt_generic_init($module, $key, $iv);		/* Decrypt encrypted string */		$decrypted = mdecrypt_generic($module, $ciphertext_dec);		/* Terminate decryption handle and close module */		mcrypt_generic_deinit($module);		mcrypt_module_close($module);		return rtrim($decrypted,"/0");	}	/**	 * Returns the length of the given string.	 * If available uses the multibyte string function mb_strlen.	 * @param string $string the string being measured for length	 * @return integer the length of the string	 */	private static function strlen($string)	{		return extension_loaded('mbstring') ? mb_strlen($string,'8bit') : strlen($string);	}	/**	 * Returns the portion of string specified by the start and length parameters.	 * If available uses the multibyte string function mb_substr	 * @param string $string the input string. Must be one character or longer.	 * @param integer $start the starting position	 * @param integer $length the desired portion length	 * @return string the extracted part of string, or FALSE on failure or an empty string.	 */	private static function substr($string,$start,$length)	{		return extension_loaded('mbstring') ? mb_substr($string,$start,$length,'8bit') : substr($string,$start,$length);	}}

php技術(shù)php寫的AES加密解密類分享,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 团结就是力量歌词完整版图片| 焕羽电视剧免费播放在线观看| 蜘蛛侠三| 电子版租房合同免费下载| 《水中花》日本电影| 李安娜| 绝路逢生| 桑叶电影| 团结就是力量歌词完整版图片| 水牛城66| 一一影视| 永夜星河导演| 欧美变态sososo另类| 夜电影| 六年级下册语文书50页内容| 粉嫩在线| 宋允雅| 画画的视频| 红楼影视| 永远的经典影片永远的| 青春之放纵作文免费阅读| 免费看黄网站在线| 许忠| 《侏罗纪公园1》电影免费观看 | nina hartley| 电视剧暗夜与黎明剧情介绍| 变形记开头结尾优美段落| 斯维特拜克之歌电影| footjob videos| 大西南电视剧| 黄视频在线网站| 肥猫正传| 欢颜电视剧40集免费观看全集高清 | 电影绿色地狱| 美国派7| 《牵牛花》阅读答案| 十万个冷笑话第二季| 红灯区1996| 简单的公告范文| 暗夜幕后在线观看完整版| 梦醒长安|