0

Im trying to update my function from PHP 5.5 version to PHP 7. But result is return diffrent in both function. PHP 5.5 result is correct and PHP 7 result is wrong. What is tha alternative solutions for this code?. Anyone aware of this function?

PHP 5.5 - Result is correct

public function decrypt($input){

    $input  = base64_decode($input);
    $result = mcrypt_decrypt(MCRYPT_DES, $this->key3,$input,  MCRYPT_MODE_CBC, $this->iv);
    return $result;
}

PHP 7.1.0 Result not correct.

public function decrypt($input){
    $inputs  = base64_decode($input);
    $result =   openssl_decrypt($input,'AES-256-CBC', $this->key3, OPENSSL_RAW_DATA, $this->iv);
    return $result;
}
Vel
  • 9,027
  • 6
  • 34
  • 66
  • Your mycrypt call uses DES to try and decrypt, but the openssl call uses AES to try and decrypt. Unsurprising that they don't produce the same result... – ADyson Mar 06 '20 at 08:59
  • @ADyson, Could you please explain? what is the alternative solutions for `MCRYPT_DES` in php 7? – Vel Mar 06 '20 at 09:01
  • 1
    They are different encryption ciphers, so obviously if something has been encrypted with one cipher, you cannot decrypt it with a different one. I suggest you google "php mycrypt replacement" or similar terms, there are a lot of existing answers on this topic. If you still can't solve it from all of those previous posts, post more info. – ADyson Mar 06 '20 at 09:04
  • P.S. DES can be cracked by brute-force with modern computing power. So if you have any control over the encryption process for this data, you would be recommended to use a stronger encryption cipher anyway. – ADyson Mar 06 '20 at 09:06
  • @ADyson, I tried with so many options. Im playing with this code last 3 days. But I cannot solve. Which information is you needed? – Vel Mar 06 '20 at 09:06
  • Anyway if you really have to continue with weak DES encryption, did you try this one, for example? https://stackoverflow.com/questions/48314953/decrypt-des-with-openssl-decrypt-in-php. Or https://stackoverflow.com/questions/55359336/openssl-decryption-des-returns-false-in-php , perhaps? This is also a useful piece of advice, depending on what kind of data you are decrypting: https://stackoverflow.com/questions/41272257/mcrypt-is-deprecated-what-is-the-alternative – ADyson Mar 06 '20 at 09:17
  • @ADyson, Those solutions not working for me. Thank you for your help. – Vel Mar 06 '20 at 10:42

0 Answers0