Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Commit

Permalink
Corrected variable name and exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ionux committed Sep 27, 2014
1 parent 5410c54 commit 8730385
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/Bitpay/Bitauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,32 +334,32 @@ public function validateSin($sin)
}

/**
* Returns the inititialization size used for a particular cypher
* Returns the inititialization size used for a particular cipher
* type. Returns an integer IV size on success or boolean false
* on failure. If no IV is needed for the cypher type and mode,
* on failure. If no IV is needed for the cipher type and mode,
* a zero is returned.
*
* @param string $cypher_type
* @param string $cipher_type
* @return int|bool
*/
public function getIVSize($cypher_type = 'MCRYPT_TRIPLEDES')
public function getIVSize($cipher_type = 'MCRYPT_TRIPLEDES')
{
$block_mode = 'cbc';

return mcrypt_get_iv_size($cypher_type, $block_mode);
return mcrypt_get_iv_size($cipher_type, $block_mode);
}

/**
* Returns the maximum key size that can be used with a particular
* cypher type. Any key size equal to or less than the returned
* cipher type. Any key size equal to or less than the returned
* value are legal key sizes. Depending on if the local mycrypt
* extension is linked against 2.2 or 2.3/2.4 the block mode could
* be required, hence the if/else statement.
*
* @param string $cypher_type
* @param string $cipher_type
* @return int
*/
public function getKeySize($cypher_type = 'MCRYPT_TRIPLEDES')
public function getKeySize($cipher_type = 'MCRYPT_TRIPLEDES')
{
$block_mode = 'cbc';

Expand Down Expand Up @@ -388,31 +388,31 @@ public function getAlgos()
* returns either boolean true/false depending on if the self-test passed
* or failed.
*
* @param string $cypher_type
* @param string $cipher_type
* @return boolean
*/
public function algoSelfTest($cypher_type = 'MCRYPT_TRIPLEDES')
public function algoSelfTest($cipher_type = 'MCRYPT_TRIPLEDES')
{
return mcrypt_module_self_test($cypher_type);
return mcrypt_module_self_test($cipher_type);
}

/**
*
* Encrypts $text based on your $key and $iv. The returned text is
* base-64 encoded to make it easier to work with in various scenarios.
* Default cypher is MCRYPT_TRIPLEDES but you can substitute depending
* Default cipher is MCRYPT_TRIPLEDES but you can substitute depending
* on your specific encryption needs.
*
* @param string $text
* @param string $key
* @param string $iv
* @param int $bit_check
* @param string $cypher_type
* @param string $cipher_type
* @return string $text
* @throws Exception $e
*
*/
public function encrypt($text, $key = '', $iv = '', $bit_check = 8, $cypher_type = 'MCRYPT_TRIPLEDES')
public function encrypt($text, $key = '', $iv = '', $bit_check = 8, $cipher_type = 'MCRYPT_TRIPLEDES')
{
try {
/* Ensure the key & IV is the same for both encrypt & decrypt. */
Expand All @@ -424,7 +424,7 @@ public function encrypt($text, $key = '', $iv = '', $bit_check = 8, $cypher_type
$text = $text.chr($text_num);
}

$cipher = mcrypt_module_open($cypher_type, '', 'cbc', '');
$cipher = mcrypt_module_open($cipher_type, '', 'cbc', '');
mcrypt_generic_init($cipher, $key, $iv);

$encrypted = mcrypt_generic($cipher, $text);
Expand All @@ -436,33 +436,33 @@ public function encrypt($text, $key = '', $iv = '', $bit_check = 8, $cypher_type
} else {
return $text;
}
} catch (Exception $e) {
return 'Error in Bitauth::Encrypt(): '.$e->getMessage();
} catch (\Exception $e) {
throw $e;
}
}

/**
*
* Decrypts $text based on your $key and $iv. Make sure you use the same key
* and initialization vector that you used when encrypting the $text. Default
* cypher is MCRYPT_TRIPLEDES but you can substitute depending on the cypher
* cipher is MCRYPT_TRIPLEDES but you can substitute depending on the cipher
* used for encrypting the text - very important.
*
* @param string $encrypted_text
* @param string $key
* @param string $iv
* @param int $bit_check
* @param string $cypher_type
* @param string $cipher_type
* @return string $text
* @throws Exception $e
*
*/
public function decrypt($encrypted_text, $key = '', $iv = '', $bit_check = 8, $cypher_type = 'MCRYPT_TRIPLEDES')
public function decrypt($encrypted_text, $key = '', $iv = '', $bit_check = 8, $cipher_type = 'MCRYPT_TRIPLEDES')
{
try {
/* Ensure the key & IV is the same for both encrypt & decrypt. */
if (!empty($encrypted_text)) {
$cipher = mcrypt_module_open($cypher_type, '', 'cbc', '');
$cipher = mcrypt_module_open($cipher_type, '', 'cbc', '');

mcrypt_generic_init($cipher, $key, $iv);
$decrypted = mdecrypt_generic($cipher, base64_decode($encrypted_text));
Expand All @@ -483,8 +483,8 @@ public function decrypt($encrypted_text, $key = '', $iv = '', $bit_check = 8, $c
} else {
return $encrypted_text;
}
} catch (Exception $e) {
return 'Error in Bitauth::Dncrypt(): '.$e->getMessage();
} catch (\Exception $e) {
throw $e;
}
}
}

0 comments on commit 8730385

Please sign in to comment.