Class AES {
const KEY = "625202f9149e061d";const IV = "5efd3f6060e20330";/**
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) {//String to Hex
$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 encryption on the Internet to find the code has PHP and Android to a bit good-hearted people speak $aes = new Aes (); $aes->aes128cbcencrypt (' token '); each step of this encryption process or help to write a corresponding JS version of = =
Reply content:
Class AES {
const KEY = "625202f9149e061d";const IV = "5efd3f6060e20330";/**
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) {//String to Hex
$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 encryption on the Internet to find the code has PHP and Android to a bit good-hearted people speak $aes = new Aes (); $aes->aes128cbcencrypt (' token '); each step of this encryption process or help to write a corresponding JS version of = =
It's quite complicated, you see this link.
http://yinghuayuan8866.blog.163.com/blog/static/2245702720121225658625/