<?php
function aes_decode($message, $encodingaeskey = '', $appid = '') {
$key = base64_decode($encodingaeskey . '=');
$ciphertext_dec = base64_decode($message);
$iv = substr($key, 0, 16);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($module, $key, $iv);
$decrypted = mdecrypt_generic($module, $ciphertext_dec);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
$pad = ord(substr($decrypted, -1));
if ($pad < 1 || $pad > 32) {
$pad = 0;
}
<?php
function aes_decode($message, $encodingaeskey = '', $appid = '') {
$key = base64_decode($encodingaeskey . '=');
$ciphertext_dec = base64_decode($message);
$iv = substr($key, 0, 16);
/* mcrypt对称解密代码在PHP7.1已经被抛弃了,所以使用下面的openssl来代替
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($module, $key, $iv);
$decrypted = mdecrypt_generic($module, $ciphertext_dec);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
*/
$decrypted = openssl_decrypt($ciphertext_dec, 'AES-256-CBC', $key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
$pad = ord(substr($decrypted, -1));
if ($pad < 1 || $pad > 32) {
$pad = 0;
}
<?php
function aes_encode($message, $encodingaeskey = '', $appid = '') {
$key = base64_decode($encodingaeskey . '=');
$text = random(16) . pack("N", strlen($message)) . $message . $appid;
$iv = substr($key, 0, 16);
$block_size = 32;
$text_length = strlen($text);
$amount_to_pad = $block_size - ($text_length % $block_size);
if ($amount_to_pad == 0) {
$amount_to_pad = $block_size;
}
$pad_chr = chr($amount_to_pad);
$tmp = '';
for ($index = 0; $index < $amount_to_pad; $index++) {
$tmp .= $pad_chr;
}
$text = $text . $tmp;
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($module, $key, $iv);
$encrypted = mcrypt_generic($module, $text);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
$encrypt_msg = base64_encode($encrypted);
return $encrypt_msg;
}
<?php
function aes_encode($message, $encodingaeskey = '', $appid = '') {
$key = base64_decode($encodingaeskey . '=');
$text = random(16) . pack("N", strlen($message)) . $message . $appid;
$iv = substr($key, 0, 16);
$block_size = 32;
$text_length = strlen($text);
$amount_to_pad = $block_size - ($text_length % $block_size);
if ($amount_to_pad == 0) {
$amount_to_pad = $block_size;
}
$pad_chr = chr($amount_to_pad);
$tmp = '';
for ($index = 0; $index < $amount_to_pad; $index++) {
$tmp .= $pad_chr;
}
$text = $text . $tmp;
/* mcrypt对称加密代码在PHP7.1已经被抛弃了,所以使用下面的openssl来代替
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($module, $key, $iv);
$encrypted = mcrypt_generic($module, $text);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
*/
$encrypted = openssl_encrypt($text, 'AES-256-CBC', $key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
$encrypt_msg = base64_encode($encrypted);
return $encrypt_msg;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有