From a16ea70cdca6dccf20f9dfc0a0f20c33b056083e Mon Sep 17 00:00:00 2001 From: Ryan Parman Date: Tue, 8 Sep 2015 18:06:06 -0700 Subject: [PATCH] Updated the source code to use the current version of the phpseclib API. Version-locked the phpseclib dependency to a known-good version. --- composer.json | 4 ++-- src/DUKPT/Utility.php | 56 +++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index 95a95da..0145d4b 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ ], "minimum-stability": "dev", "require": { - "php": ">=5.3.0", - "phpseclib/phpseclib": "*" + "php": ">=5.3.3", + "phpseclib/phpseclib": "^2.0" }, "autoload": { "psr-0": { diff --git a/src/DUKPT/Utility.php b/src/DUKPT/Utility.php index 33a668a..564af2c 100644 --- a/src/DUKPT/Utility.php +++ b/src/DUKPT/Utility.php @@ -2,17 +2,17 @@ namespace DUKPT; -use Crypt; +use phpseclib\Crypt\TripleDES; class Utility { /** * Convert hexadecimal string to binary - * + * * This function is available in PHP > 5.4 - * + * * @param string $hexString - * + * * @return binary */ public static function hex2bin($hexString) @@ -28,9 +28,9 @@ public static function hex2bin($hexString) /** * Convert hexadecimal string to its binary string representation - * + * * @param string $hexString - * + * * @return string */ public static function hex2binstr($hexString) @@ -51,9 +51,9 @@ public static function hex2binstr($hexString) /** * Convert a binary string to its hexadecimal string representation - * + * * @param string $binaryString - * + * * @return string */ public static function binstr2hex($binaryString) @@ -79,7 +79,7 @@ public static function binstr2hex($binaryString) * Second hexadecimal string * @param int $offset * Offset in bits - * + * * @return string * ANDed result */ @@ -112,7 +112,7 @@ public static function andHexString($input, $mask, $offset = 0) * Second hexadecimal string * @param int $offset * Offset in bits - * + * * @return string * ORed result */ @@ -145,7 +145,7 @@ public static function orHexString($input, $mask, $offset = 0) * Second hexadecimal string * @param int $offset * Offset in bits - * + * * @return string * XORed result */ @@ -171,7 +171,7 @@ public static function xorHexString($input, $mask, $offset = 0) * * @param string $hexString * Input string - * + * * @return string * Shifted string */ @@ -184,12 +184,12 @@ public static function shiftRightHexString($hexString) /** * DES Encrypt in ECB mode - * + * * @param string $hexData * Data in hexadecimal representation * @param string $hexKey * Key in hexadecimal representation - * + * * @return string * Encrypted data in hexadecimal representation */ @@ -201,12 +201,12 @@ public static function desEncrypt($hexData, $hexKey) /** * DES Decrypt in ECB mode - * + * * @param string $hexData * Ecrypted data in hexadecimal representation * @param string $hexKey * Key in hexadecimal representation - * + * * @return string * Decrypted data in hexadecimal representation */ @@ -218,12 +218,12 @@ public static function desDecrypt($hexData, $hexKey) /** * 3-DES Encrypt in EDE-CBC3 Mode - * + * * @param string $hexData * Data in hexadecimal representation * @param string $hexKey * Key in hexadecimal representation - * + * * @return string * Encrypted data in hexadecimal representation */ @@ -232,7 +232,7 @@ public static function tripleDesEncrypt($hexData, $hexKey) //fix Crypt Library padding $hexKey = $hexKey . substr($hexKey, 0, 16); - $crypt3DES = new \Crypt_TripleDES(CRYPT_DES_MODE_CBC3); + $crypt3DES = new TripleDES(TripleDES::MODE_CBC3); $crypt3DES->setKey(Utility::hex2bin($hexKey)); $crypt3DES->disablePadding(); @@ -241,14 +241,14 @@ public static function tripleDesEncrypt($hexData, $hexKey) /** * 3-DES Decrypt in EDE-CBC3 Mode - * + * * @param string $hexEncryptedData * Encrypted Data in hexadecimal representation * @param string $hexKey * Key in hexadecimal representation * @param bool $useDesModeCBC3 * Use DES CBC3 Mode - * + * * @return string * Decrypted data in hexadecimal representation */ @@ -258,9 +258,9 @@ public static function tripleDesDecrypt($hexEncryptedData, $hexKey, $useDesModeC $hexKey = $hexKey . substr($hexKey, 0, 16); if ($useDesModeCBC3) { - $crypt3DES = new \Crypt_TripleDES(CRYPT_DES_MODE_CBC3); // IDTech uses mode CRYPT_DES_MODE_CBC3 + $crypt3DES = new TripleDES(TripleDES::MODE_CBC3); // IDTech uses mode CRYPT_DES_MODE_CBC3 } else { - $crypt3DES = new \Crypt_TripleDES(CRYPT_DES_MODE_ECB); // Chinese uses mode CRYPT_DES_MODE_ECB + $crypt3DES = new TripleDES(TripleDES::MODE_ECB); // Chinese uses mode CRYPT_DES_MODE_ECB } $crypt3DES->setKey(Utility::hex2bin($hexKey)); $crypt3DES->disablePadding(); @@ -270,10 +270,10 @@ public static function tripleDesDecrypt($hexEncryptedData, $hexKey, $useDesModeC /** * Get a specific byte in a hex string - * + * * @param string $hexString * @param string $byteNumber - * + * * @return string Byte */ public static function getByteOnHexString($hexString, $byteNumber) @@ -283,11 +283,11 @@ public static function getByteOnHexString($hexString, $byteNumber) /** * Set a specific byte in a hex string - * + * * @param string $hexString * @param string $byte * @param int $byteNumber - * + * * @return string Hex String */ public static function setByteOnHexString($hexString, $byte, $byteNumber) @@ -312,7 +312,7 @@ public static function setByteOnHexString($hexString, $byte, $byteNumber) /** * Remove NUL padding from string - * + * * @param string $hexString * @return string */