Home > php教程 > php手册 > PHP aes (ecb)解密后乱码问题,aesecb

PHP aes (ecb)解密后乱码问题,aesecb

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 09:00:06
Original
955 people have browsed it

PHP aes (ecb)解密后乱码问题,aesecb

内容:abcd
KEY:1234567890123456
加密后base64:T7UT2NQ1AFvR9unjA0wKWA==

function apiDataDecrypt($data, $key='') {
  $data = base64_decode($data);
  $pad = 16 - (strlen($data) % 16);
  $padData = $data . str_repeat(chr($pad), $pad);
  return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key,$padData, MCRYPT_MODE_ECB);
}    
}

Copy after login

直接附上解决方案吧

$key = '1234567890123456';
$content = 'T7UT2NQ1AFvR9unjA0wKWA==';
$desStr = decryptString($content,$key);
echo($desStr);

function decryptString($str,$key) {
  $str = base64_decode($str);
  $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB);  
  $block = mcrypt_get_block_size('rijndael_128', 'ecb');
  $pad = ord($str[($len = strlen($str)) - 1]);
  $len = strlen($str);
  $pad = ord($str[$len-1]);  
  return substr($str, 0, strlen($str) - $pad);
}

Copy after login

以上所述就是本文的全部内容了,希望大家能够喜欢。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template