You are here

function _commerce_sagepay_addPKCS5Padding in Drupal Commerce SagePay Integration 7

PHP's mcrypt does not have built in PKCS5 Padding, so we use this.

Parameters

string $input: The input string.

Return value

string The string with padding.

1 call to _commerce_sagepay_addPKCS5Padding()
_commerce_sagepay_encrypt_and_encode in includes/commerce_sagepay_utils.inc
Encrypt a string ready to send to SagePay using encryption key.

File

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

Code

function _commerce_sagepay_addPKCS5Padding($input) {
  $blocksize = 16;
  $padding = "";

  // Pad input to an even block size boundary.
  $padlength = $blocksize - strlen($input) % $blocksize;
  for ($i = 1; $i <= $padlength; $i++) {
    $padding .= chr($padlength);
  }
  return $input . $padding;
}