cleaned up some code
This commit is contained in:
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
// Change for phpMyAdmin by lem9:
|
// Change for phpMyAdmin by lem9:
|
||||||
//class Horde_Cipher_blowfish extends Horde_Cipher {
|
//class Horde_Cipher_blowfish extends Horde_Cipher {
|
||||||
class Horde_Cipher_blowfish {
|
class Horde_Cipher_blowfish
|
||||||
|
{
|
||||||
/* Pi Array */
|
/* Pi Array */
|
||||||
var $p = array(
|
var $p = array(
|
||||||
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
|
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
|
||||||
@@ -294,11 +294,6 @@ class Horde_Cipher_blowfish {
|
|||||||
/* The number of rounds to do */
|
/* The number of rounds to do */
|
||||||
var $_rounds = 16;
|
var $_rounds = 16;
|
||||||
|
|
||||||
/* Constructor */
|
|
||||||
function Cipher_blowfish($params = null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the key to be used for en/decryption
|
* Set the key to be used for en/decryption
|
||||||
*
|
*
|
||||||
@@ -358,16 +353,6 @@ class Horde_Cipher_blowfish {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the size of the blocks that this cipher needs
|
|
||||||
*
|
|
||||||
* @return Integer The number of characters per block
|
|
||||||
*/
|
|
||||||
function getBlockSize()
|
|
||||||
{
|
|
||||||
return 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt a block on data.
|
* Encrypt a block on data.
|
||||||
*
|
*
|
||||||
@@ -481,38 +466,6 @@ class Horde_Cipher_blowfish {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// higher-level functions:
|
// higher-level functions:
|
||||||
|
|
||||||
/**
|
|
||||||
* String padding
|
|
||||||
*
|
|
||||||
* @param string input string
|
|
||||||
* @param integer length of the result
|
|
||||||
* @param string the filling string
|
|
||||||
* @param integer padding mode
|
|
||||||
*
|
|
||||||
* @return string the padded string
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
function full_str_pad($input, $pad_length, $pad_string = '', $pad_type = 0) {
|
|
||||||
$str = '';
|
|
||||||
$length = $pad_length - strlen($input);
|
|
||||||
if ($length > 0) { // str_repeat doesn't like negatives
|
|
||||||
if ($pad_type == STR_PAD_RIGHT) { // STR_PAD_RIGHT == 1
|
|
||||||
$str = $input.str_repeat($pad_string, $length);
|
|
||||||
} elseif ($pad_type == STR_PAD_BOTH) { // STR_PAD_BOTH == 2
|
|
||||||
$str = str_repeat($pad_string, floor($length/2));
|
|
||||||
$str .= $input;
|
|
||||||
$str .= str_repeat($pad_string, ceil($length/2));
|
|
||||||
} else { // defaults to STR_PAD_LEFT == 0
|
|
||||||
$str = str_repeat($pad_string, $length).$input;
|
|
||||||
}
|
|
||||||
} else { // if $length is negative or zero we don't need to do anything
|
|
||||||
$str = $input;
|
|
||||||
}
|
|
||||||
return $str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encryption using blowfish algorithm
|
* Encryption using blowfish algorithm
|
||||||
*
|
*
|
||||||
@@ -525,15 +478,19 @@ function full_str_pad($input, $pad_length, $pad_string = '', $pad_type = 0) {
|
|||||||
*
|
*
|
||||||
* @author lem9
|
* @author lem9
|
||||||
*/
|
*/
|
||||||
function PMA_blowfish_encrypt($data, $secret) {
|
function PMA_blowfish_encrypt($data, $secret)
|
||||||
|
{
|
||||||
$pma_cipher = new Horde_Cipher_blowfish;
|
$pma_cipher = new Horde_Cipher_blowfish;
|
||||||
$encrypt = '';
|
$encrypt = '';
|
||||||
for ($i=0; $i<strlen($data); $i+=8) {
|
|
||||||
$block = substr($data, $i, 8);
|
$mod = strlen($data) % 8;
|
||||||
if (strlen($block) < 8) {
|
|
||||||
$block = full_str_pad($block, 8, "\0", 1);
|
if ($mod > 0) {
|
||||||
|
$data .= str_repeat("\0", 8 - $mod);
|
||||||
}
|
}
|
||||||
$encrypt .= $pma_cipher->encryptBlock($block, $secret);
|
|
||||||
|
foreach (str_split($data, 8) as $chunk) {
|
||||||
|
$encrypt .= $pma_cipher->encryptBlock($chunk, $secret);
|
||||||
}
|
}
|
||||||
return base64_encode($encrypt);
|
return base64_encode($encrypt);
|
||||||
}
|
}
|
||||||
@@ -550,12 +507,14 @@ function PMA_blowfish_encrypt($data, $secret) {
|
|||||||
*
|
*
|
||||||
* @author lem9
|
* @author lem9
|
||||||
*/
|
*/
|
||||||
function PMA_blowfish_decrypt($encdata, $secret) {
|
function PMA_blowfish_decrypt($encdata, $secret)
|
||||||
|
{
|
||||||
$pma_cipher = new Horde_Cipher_blowfish;
|
$pma_cipher = new Horde_Cipher_blowfish;
|
||||||
$decrypt = '';
|
$decrypt = '';
|
||||||
$data = base64_decode($encdata);
|
$data = base64_decode($encdata);
|
||||||
for ($i=0; $i<strlen($data); $i+=8) {
|
|
||||||
$decrypt .= $pma_cipher->decryptBlock(substr($data, $i, 8), $secret);
|
foreach (str_split($data, 8) as $chunk) {
|
||||||
|
$decrypt .= $pma_cipher->decryptBlock($chunk, $secret);
|
||||||
}
|
}
|
||||||
return trim($decrypt);
|
return trim($decrypt);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user