在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
PHP AES CBC模式PKCS7 128位加密 加密: $key = '1234567812345678'; $iv = '1234567890123456'; $message = '123456'; $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $len = strlen($message); //取得字符串长度 $pad = $blocksize - ($len % $blocksize); //取得补码的长度 $message .= str_repeat(chr($pad), $pad); //用ASCII码为补码长度的字符, 补足最后一段 $xcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $message, MCRYPT_MODE_CBC, $iv); PHP AES CBC模式PKCS7 128位解密 解密: public function stripPkcs7Padding($string) { $slast = ord(substr($string, -1)); $slastc = chr($slast); $pcheck = substr($string, -$slast); if (preg_match("/$slastc{" . $slast . "}/", $string)) { $string = substr($string, 0, strlen($string) - $slast); return $string; } else { return false; } } stripPkcs7Padding(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $xcrypt, MCRYPT_MODE_CBC, $iv))
http://php.net/manual/zh/function.mcrypt-encrypt.php
转: https://blog.csdn.net/u011650048/article/details/50846124
|
请发表评论