serpro / Android-PHP-Encrypt-Decrypt

Encrypt / Decrypt Between Android and PHP and vice-versa
155 stars 74 forks source link

Error when use php 7 #26

Open isarjanfaza opened 6 years ago

isarjanfaza commented 6 years ago

hi when use php version 7 not work and get error {main} thrown in MCrypt.php on line 11

please check this bug

thanks

Goufalite commented 5 years ago

In PHP 7, MCrypt is deprecated... A workaround is to use openssl_* instead :

function encrypt2($str) {

            $encrypted = openssl_encrypt($str, 'aes-128-cbc', KEY_SERVICE, OPENSSL_RAW_DATA, IV_SERVICE);

            return bin2hex($encrypted);
          }

          function decrypt2($code) {
            $code = $this->hex2bin($code);

            $decrypted = openssl_decrypt($code, 'aes-128-cbc', KEY_SERVICE, OPENSSL_RAW_DATA |  OPENSSL_ZERO_PADDING, IV_SERVICE);

            return trim($decrypted);
          }
serpro commented 5 years ago

Thanks @Goufalite for the suggestion.

Would you like to create a pull request to contribute with the code?

Goufalite commented 5 years ago

I have to check something with the ZERO_PADDING option which messes with the result, then I'll make the pull request

razmjooDev commented 4 years ago

hi @Goufalite how to set java class for this code?

Goufalite commented 4 years ago

Look at the code tab on top, there's a Java MCrypt class.

I still have some leading NULL characters at the beginning so some trim might be in order to process the strings.

razmjooDev commented 4 years ago

i used that Java class but the results were not the same as your code results

Goufalite commented 4 years ago

What were the results?