PHP aes (ecb) garbled characters After decryption

Source: Internet
Author: User

PHP aes (ecb) garbled characters After decryption

This article describes how to solve the garbled problem after decryption by PHP aes (ecb). It is very simple and practical. If you need it, you can refer to it.

Content: abcd

KEY: 1234567890123456.

Encrypted base64: T7UT2NQ1AFvR9unjA0wKWA =

?

1

2

3

4

5

6

7

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 );

}

}

Directly attach the solution

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

$ Key = '000000 ';

$ 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 _ 000000', 'ecb ');

$ Pad = ord ($ str [($ len = strlen ($ str)-1]);

$ Len = strlen ($ str );

$ Pad = ord ($ str [$ len-1]);

Return substr ($ str, 0, strlen ($ str)-$ pad );

}

The above is all the content of this article. I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.