Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependency issues #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
56 changes: 28 additions & 28 deletions src/DUKPT/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -79,7 +79,7 @@ public static function binstr2hex($binaryString)
* Second hexadecimal string
* @param int $offset
* Offset in bits
*
*
* @return string
* ANDed result
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand All @@ -171,7 +171,7 @@ public static function xorHexString($input, $mask, $offset = 0)
*
* @param string $hexString
* Input string
*
*
* @return string
* Shifted string
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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();

Expand All @@ -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
*/
Expand All @@ -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();
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -312,7 +312,7 @@ public static function setByteOnHexString($hexString, $byte, $byteNumber)

/**
* Remove NUL padding from string
*
*
* @param string $hexString
* @return string
*/
Expand Down