class aes {
<code>const KEY = "625202f9149e061d"; const IV = "5efd3f6060e20330"; /**</code>
pkcs7補碼
@param string $string 明文
@param int $blocksize Blocksize , 以 byte 為單位
@return String
*/
function addPkcs7Padding($string, $blocksize = 32) {
<code> $len = strlen($string); //取得字符串长度 $pad = $blocksize - ($len % $blocksize); //取得补码的长度 $string .= str_repeat(chr($pad), $pad); //用ASCII码为补码长度的字符, 补足最后一段 return $string;</code>
}
aes128cbcEncrypt($str, $iv = self::IV, $key = self::KEY) { // $this->addPkcs7Padding($str,16)
<code> $base = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $this->addPkcs7Padding($str, 16), MCRYPT_MODE_CBC, $iv)); return $this->strToHex($base);</code>
}
strToHex($string) {//字串轉十六進位
<code> $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;</code>
}
aes加密在網路上找的程式碼有PHP 和android 的來位好心人講講$aes = new aes(); $aes->aes128cbcEncrypt('token');這個加密過程的每一步唄或幫忙寫一份對應的js版本的= =
class aes {
<code>const KEY = "625202f9149e061d"; const IV = "5efd3f6060e20330"; /**</code>
pkcs7補碼
@param string $string 明文
@param int $blocksize Blocksize , 以 byte 為單位
@return String
*/
function addPkcs7Padding($string, $blocksize = 32) {
<code> $len = strlen($string); //取得字符串长度 $pad = $blocksize - ($len % $blocksize); //取得补码的长度 $string .= str_repeat(chr($pad), $pad); //用ASCII码为补码长度的字符, 补足最后一段 return $string;</code>
}
aes128cbcEncrypt($str, $iv = self::IV, $key = self::KEY) { // $this->addPkcs7Padding($str,16)
<code> $base = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $this->addPkcs7Padding($str, 16), MCRYPT_MODE_CBC, $iv)); return $this->strToHex($base);</code>
}
strToHex($string) {//字串轉十六進位
<code> $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;</code>
}
aes加密在網路上找的程式碼有PHP 和android 的來位好心人講講$aes = new aes(); $aes->aes128cbcEncrypt('token');這個加密過程的每一步唄或幫忙寫一份對應的js版本的= =
說起來挺複雜的,你看看這個連結吧。
http://yinghuayuan8866.blog.163.com/blog/static/2245702720121225658625/