You are here

function _commerce_sagepay_encrypt_and_encode in Drupal Commerce SagePay Integration 7

Encrypt a string ready to send to SagePay using encryption key.

Parameters

string $string: The unencrypyted string.

string $key: The encryption key.

Return value

string The encoded string.

1 call to _commerce_sagepay_encrypt_and_encode()
_commerce_sagepay_encrypted_order in includes/commerce_sagepay_common.inc
Encrypt the order details ready to send to SagePay Server.

File

includes/commerce_sagepay_utils.inc, line 70
commerce_sagepay_utils.inc Common utilities shared by all Integration methods.

Code

function _commerce_sagepay_encrypt_and_encode($string, $key) {

  // AES encryption, CBC blocking with PKCS5 padding then HEX encoding.
  // Add PKCS5 padding to the text to be encypted.
  $string = _commerce_sagepay_addPKCS5Padding($string);

  // Perform encryption with PHP's MCRYPT module.
  $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $key);

  // Perform hex encoding and return.
  return "@" . bin2hex($crypt);
}