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) {//字串轉十六進位
$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版本的 = =
回複內容:
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) {//字串轉十六進位
$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/