Skip to content

Instantly share code, notes, and snippets.

@dakshhmehta
Created August 27, 2019 11:46
Show Gist options
  • Save dakshhmehta/ad49074aa6e9dd3ceb8a0d30dc087c9e to your computer and use it in GitHub Desktop.
Save dakshhmehta/ad49074aa6e9dd3ceb8a0d30dc087c9e to your computer and use it in GitHub Desktop.
/**
* CCAvenue Encrypt Function
*
* @param $plainText
* @param $key
* @return string
*/
protected function encrypt($plainText, $key)
{
$key = $this->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;
}
/**
* CCAvenue Decrypt Function
*
* @param $encryptedText
* @param $key
* @return string
*/
protected function decrypt($encryptedText, $key)
{
$key = $this->hextobin(md5($key));
$initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
$encryptedText = $this->hextobin($encryptedText);
$decryptedText = openssl_decrypt($encryptedText, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $initVector);
return $decryptedText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment