class aes {
const KEY = "625202f9149e061d";
const IV = "5efd3f6060e20330";
/**
pkcs7补码
@param string $string 明文
@param int $blocksize Blocksize , 以 byte 为单位
@return String
*/
-
function addPkcs7Padding($string, $blocksize = 32) {
$len = strlen($string); //取得字符串长度 $pad = $blocksize - ($len % $blocksize); //取得补码的长度 $string .= str_repeat(chr($pad), $pad); //用ASCII码为补码长度的字符, 补足最后一段 return $string;
}
-
aes128cbcEncrypt($str, $iv = self::IV, $key = self::KEY) { // $this->addPkcs7Padding($str,16)
$base = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $this->addPkcs7Padding($str, 16), MCRYPT_MODE_CBC, $iv)); return $this->strToHex($base);
}
-
strToHex($string) {//字符串转十六进制
$hex = ""; $tmp = ""; for ($i = 0; $i < strlen($string); $i++) { $tmp = dechex(ord($string[$i])); $hex.= strlen($tmp) == 1 ? "0" . $tmp : $tmp; } $hex = strtoupper($hex); return $hex;
}
aes加密 在网上找的代码有PHP 和 android 的 来位好心人讲讲$aes = new aes(); $aes->aes128cbcEncrypt('token');这个加密过程的每一步呗 或者帮忙写一份对应的js版本的 = =
说起来挺复杂的,你看看这个链接吧。
http://yinghuayuan8866.blog.163.com/blog/static/2245702720121225658625/