Skip to content

Commit

Permalink
Added suport to mcrypt and openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
eusonlito committed Apr 18, 2017
1 parent fe0304a commit af9e434
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Redsys/Tpv/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,29 @@ private static function calculate($prefix, array $fields, array $values, $key)
}

private static function encrypt3DES($message, $key)
{
if (function_exists('openssl_encrypt')) {
return self::encrypt3DESOpenSSL($message, $key);
}

return self::encrypt3DESMcrypt($message, $key);
}

private static function encrypt3DESOpenSSL($message, $key)
{
$l = ceil(strlen($message) / 8) * 8;
$message = $message.str_repeat("\0", $l - strlen($message));

return substr(openssl_encrypt($message, 'des-ede3-cbc', $key, OPENSSL_RAW_DATA, "\0\0\0\0\0\0\0\0"), 0, $l);
}

private static function encrypt3DESMcrypt($message, $key)
{
$iv = implode(array_map('chr', array(0, 0, 0, 0, 0, 0, 0, 0)));

return mcrypt_encrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_CBC, $iv);
}

private static function encryptKey($order, $key)
{
return self::encrypt3DES($order, base64_decode($key));
Expand Down

0 comments on commit af9e434

Please sign in to comment.