小陆博客

为站长提供建站技巧、网站运营、搜索优化、建站方向以及利用网站赚钱与创业的知识与经验。

热门搜索:

php aes 128 ecb pkcs5padding-掘金

1342 浏览
0 评论
内容
``` php public static function hmac($algo, $data, $key, $raw_output = false) { if (function_exists('hash_hmac') && !defined('SIMPLE_TEST')) { return hash_hmac($algo, $data, $key, $raw_output); } $algo = strtolower($algo); $pack = 'H' . strlen($algo('test')); $size = 64; $opad = str_repeat(chr(0x5C), $size); $ipad = str_repeat(chr(0x36), $size); if (strlen($key) > $size) { $key = str_pad(pack($pack, $algo($key)), $size, chr(0x00)); } else { $key = str_pad($key, $size, chr(0x00)); } for ($i = 0; $i < strlen($key) - 1; $i++) { $opad[$i] = $opad[$i] ^ $key[$i]; $ipad[$i] = $ipad[$i] ^ $key[$i]; } $output = $algo($opad . pack($pack, $algo($ipad . $data))); return ($raw_output) ? pack($pack, $output) : $output; } public function encrypt($input, $config) { return base64_encode(openssl_encrypt($input, 'AES-128-CBC', $config['data_secret'], OPENSSL_RAW_DATA, $config['data_secret_iv'])); } // 解密 public function decrypt($input, $config) { return openssl_decrypt(base64_decode($input), 'AES-128-CBC', $config['data_secret'], OPENSSL_RAW_DATA, $config['data_secret_iv']); } ```
``` php public static function hmac($algo, $data, $key, $raw_output = false) { if (function_exists('hash_hmac') && !defined('SIMPLE_TEST')) { return hash_hmac($algo, $data, $key, $raw_output); } $algo = strtolower($algo); $pack = 'H' . strlen($algo('test')); $size = 64; $opad = str_repeat(chr(0x5C), $size); $ipad = str_repeat(chr(0x36), $size); if (strlen($key) > $size) { $key = str_pad(pack($pack, $algo($key)), $size, chr(0x00)); } else { $key = str_pad($key, $size, chr(0x00)); } for ($i = 0; $i < strlen($key) - 1; $i++) { $opad[$i] = $opad[$i] ^ $key[$i]; $ipad[$i] = $ipad[$i] ^ $key[$i]; } $output = $algo($opad . pack($pack, $algo($ipad . $data))); return ($raw_output) ? pack($pack, $output) : $output; } public function encrypt($input, $config) { return base64_encode(openssl_encrypt($input, 'AES-128-CBC', $config['data_secret'], OPENSSL_RAW_DATA, $config['data_secret_iv'])); } // 解密 public function decrypt($input, $config) { return openssl_decrypt(base64_decode($input), 'AES-128-CBC', $config['data_secret'], OPENSSL_RAW_DATA, $config['data_secret_iv']); } ```

评论 (0)

评论功能正在开发中...