0

I use this lib to create AES encrypt string on Android and add this string to MySQL.

This is parameter of lib:

enter image description here

Now I want to decrypt the String by PHP:

This is encrypt string:

Plaintext: a
z8OVzJvtKHPCdT6PeFoEww==(encrypt)

Then I want decrypt this string on my webserver using PHP.

I use this code, but that have something wrong:

require "connect.php";
$sql_query = "SELECT * FROM user_info";
$result = mysqli_query($con,$sql_query); 
$name_en="";
$row = mysqli_fetch_assoc($result);
$name_en = $row['name'];
echo $name_en;
$password = "123456789";
$iv = "0000000000000000";
echo "<br/>";
echo $password;
echo "<br/>";
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'','cbc','');
mcrypt_generic_init($cipher, $password, $iv);
$decrypted = mdecrypt_generic($cipher,base64_encode($name_en));
mcrypt_generic_deinit($cipher);
echo $decrypted;

But the result is:

z8OVzJvtKHPCdT6PeFoEww==
123456789
#�7��T26�r���v��u�T[|�9`��.���

Thank for advance.

  • 1
    Possible duplicate of [PHP AES encrypt / decrypt](https://stackoverflow.com/questions/3422759/php-aes-encrypt-decrypt) – Wahyu Kristianto Jul 29 '17 at 08:42
  • It is best not to use mcrypt, it is abandonware, has not been updated in years and does not support standard PKCS#7 (née PKCS#5) padding, only non-standard null padding that can't even be used with binary data. mcrypt has many outstanding [bugs](https://sourceforge.net/p/mcrypt/bugs/) dating back to 2003. The mcrypt-extension is deprecated will be removed in PHP 7.2. Instead consider using [defuse](https://github.com/defuse/php-encryption) or [RNCryptor](https://github.com/RNCryptor), they provide a complete solution and are being maintained and is correct. – zaph Jul 29 '17 at 13:05

1 Answers1

0

if it is encrypted by AES it should be decrypted by AES . i think there are built in functions for that aes_encrypt() and aes_decrypt()

Farsay
  • 312
  • 1
  • 9
  • I do not know what you mean, I use this lib to encrypt string on Android and add to mysql. Then I want to decrypt by PHP. –  Jul 29 '17 at 08:40
  • can u try aes_decrypt() function to decrypt - its a php built in function to decrypt AES encrypted string – Farsay Jul 29 '17 at 08:43
  • Never, I don't know it, can I gave me that guide? –  Jul 29 '17 at 08:45
  • http://www.w3resource.com/mysql/encryption-and-compression-functions/aes_decrypt().php - hope this will help – Farsay Jul 29 '17 at 08:50