0
votes

CCAvenue uses MCRYPT_RIJNDAEL_128 to encrypt transaction data. Since my server is running PHP 7.1, Im unable to decrypt this data.

Is there any workaround to decrypt this string on PHP 7.1 or Do I have to downgrade to PHP 5 to get this working.

Decryption code from ccavenue

    function decrypt($encryptedText,$key)
    {
        $secretKey = hextobin(md5($key));
        $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
        $encryptedText=hextobin($encryptedText);
        $openMode = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '','cbc', '');
        mcrypt_generic_init($openMode, $secretKey, $initVector);
        $decryptedText = mdecrypt_generic($openMode, $encryptedText);
        $decryptedText = rtrim($decryptedText, "\0");
        mcrypt_generic_deinit($openMode);
        return $decryptedText;

    }

Response on decryption

Call to undefined function mcrypt_module_open()
2

2 Answers

1
votes

Ok. Turns our CCAvenue has pushed a PHP 7.1 compatible version.

Open SSL Compatible version of code

function encrypt($plainText,$key)
{
  $key = hextobin(md5($key));
  $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
  $openMode = openssl_encrypt($plainText, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $initVector);
  $encryptedText = bin2hex($openMode);
  return $encryptedText;
}

function decrypt($encryptedText,$key)
{
  $key = hextobin(md5($key));
  $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
  $encryptedText = hextobin($encryptedText);
  $decryptedText = openssl_decrypt($encryptedText, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $initVector);
  return $decryptedText;

}
0
votes

Try using openssl_encrypt($input, 'AES-128-CBC', "KEY", OPENSSL_RAW_DATA, $iv);