0

Actually i have a wordpress pluging which is used as gateway for woocommerce ,it was working fine before updating PhP 7.1 to Php 7.2 on the server. As you guys know php7.2 is not supporting mcrypt_encode & mcrypt_decode and it suggested to use openssl_encrypt instead ... the old code for encryption is as below : public function encrypt($string ="")

        {

        global $KEY,$IV;

            $key1 = base64_decode($this->KEY);

            $iv1 = base64_decode($this->IV);

            return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key1, $this->addpadding($string), MCRYPT_MODE_CBC, $iv1));

        }



        public function decrypt($string ="")

        {

        global $KEY,$IV;

            $key = base64_decode($this->KEY);

            $iv = base64_decode($this->IV);

            $string = base64_decode($string);

            return $this->strippadding(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv));

        }

I have tried to convert them to openssl as the documentation but i guess there is something that i'm not aware of or i have lack of knowledge (that is unfortunate) ...

would you guys help me to convert this code (which is above) to openssl version !?

Thanks in advance

ashkan
  • 1
  • 2
  • `MCRYPT_RIJNDAEL_256` is Rijndael with a block size of 256 bits. Rijndael supports different block sizes, see [here](https://stackoverflow.com/a/748645/9014097). AES is a subset of Rijndael with a block size of 128 bits (and the key sizes 128, 192 and 256 bits). OpenSSL supports AES, but _not_ Rijndael with a block size of 256 bits. You will probably have to switch to another library, e.g. [_phpseclib_](http://phpseclib.sourceforge.net/crypt/2.0/examples.html#rijndael,cbc,outer,k128,kr128,b256,key,padding,1.0,). – Topaco Oct 21 '20 at 16:34
  • 1
    Does this answer your question? [mcrypt is deprecated, what is the alternative?](https://stackoverflow.com/questions/41272257/mcrypt-is-deprecated-what-is-the-alternative). See especially [this](https://stackoverflow.com/a/48120485) and [this](https://stackoverflow.com/a/53937314) answer. – Topaco Oct 21 '20 at 17:09

0 Answers0