475
// higher-level functions:
480
* @param string input string
481
* @param integer length of the result
482
* @param string the filling string
483
* @param integer padding mode
485
* @return string the padded string
489
function full_str_pad($input, $pad_length, $pad_string = '', $pad_type = 0) {
491
$length = $pad_length - strlen($input);
492
if ($length > 0) { // str_repeat doesn't like negatives
493
if ($pad_type == STR_PAD_RIGHT) { // STR_PAD_RIGHT == 1
494
$str = $input.str_repeat($pad_string, $length);
495
} elseif ($pad_type == STR_PAD_BOTH) { // STR_PAD_BOTH == 2
496
$str = str_repeat($pad_string, floor($length/2));
498
$str .= str_repeat($pad_string, ceil($length/2));
499
} else { // defaults to STR_PAD_LEFT == 0
500
$str = str_repeat($pad_string, $length).$input;
502
} else { // if $length is negative or zero we don't need to do anything
509
* Encryption using blowfish algorithm
511
* @param string original data
512
* @param string the secret
514
* @return string the encrypted result
520
function PMA_blowfish_encrypt($data, $secret) {
521
$pma_cipher = new Horde_Cipher_blowfish;
523
for ($i=0; $i<strlen($data); $i+=8) {
524
$block = substr($data, $i, 8);
525
if (strlen($block) < 8) {
526
$block = full_str_pad($block,8,"\0", 1);
528
$encrypt .= $pma_cipher->encryptBlock($block, $secret);
530
return base64_encode($encrypt);
534
* Decryption using blowfish algorithm
536
* @param string encrypted data
537
* @param string the secret
539
* @return string original data
545
function PMA_blowfish_decrypt($encdata, $secret) {
546
$pma_cipher = new Horde_Cipher_blowfish;
548
$data = base64_decode($encdata);
549
for ($i=0; $i<strlen($data); $i+=8) {
550
$decrypt .= $pma_cipher->decryptBlock(substr($data, $i, 8), $secret);
552
return trim($decrypt);