如果不用在Yii框架中,把代碼中Yii::app()->params['encryptKey'] 換成你對應的默認key就可以了。
類代碼:
<&#63;php/** * php AES加解密類 * 如果要與java共用,則密鑰 " /> 午夜想想爱午夜剧场,久久香蕉国产线看观看精品,亚洲无AV在线中文字幕

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php寫的AES加密解密類分享

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

<?php/** * php AES加解密類 * 如果要與Java共用,則密鑰長度應該為16位長度 * 因為Java只支持128位加密,所以php也用128位加密,可以與Java互轉。 * 同時AES的標準也是128位。只是RIJNDAEL算法可以支持128,192和256位加密。 * Java 要使用AES/CBC/NoPadding標準來加解密 *  * @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技術php寫的AES加密解密類分享,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 午夜免费国产体验区免费的 | 亚洲网站视频在线观看 | 内射白浆一区二区在线观看 | 999久久国产精品免费人妻 | 欧美黑人巨大xxxxx | 久久久综合中文字幕久久 | 天天操人人射 | 伊人成综合网伊人222 | WWW国产精品人妻一二三区 | 亚洲欧洲无码AV在线观看你懂的 | 语文老师扒开胸罩喂我奶 | 中文字幕一区二区视频 | 亚色九九九全国免费视频 | 91avcom| 国产成人精选免费视频 | 成片在线看一区二区草莓 | 久久国产免费一区二区三区 | 亚洲国产精品免费观看 | 人性本色联盟 | 45分钟做受片免费观看 | YELLOW日本动漫免费动漫 | 在线视频免费观看 | 60岁老年熟妇在线无码 | 麻豆天美国产一区在线播放 | 久久国产主播福利在线 | 十八禁啪啦啪漫画 | 国产一区二区高清 | 中文字幕亚洲欧美日韩2o19 | 亚洲伊人久久大香线蕉综合图片 | 欧美熟妇互舔20p | 男生在床上脱美女 胸 | 在线播放av欧美无码碰 | bl高h肉文| 国产精品玖玖玖影院 | 草莓视频免费看 | 日韩一级精品久久久久 | 国产CHINESE HD精品 | 久久99精品涩AV毛片观看 | 啊叫大点声欠CAO的SAO贷 | 贵妃高h荡肉呻吟np杨玉环 | 四虎国产精品高清在线观看 |