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.