unsupported binary characters in database,

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have the following encryption function:
 

function RC4( $data) { //ecncrypt $data with the key in $keyfile with an rc4
algorithm
    $pwd = implode('', file(/key.php'));
        $pwd_length = strlen($pwd);
    for ($i = 0; $i < 255; $i++) {
          $key[$i] = ord(substr($pwd, ($i % $pwd_length)+1, 1));
            $counter[$i] = $i;
        }
        for ($i = 0; $i < 255; $i++) {
            $x = ($x + $counter[$i] + $key[$i]) % 256;
            $temp_swap = $counter[$i];
            $counter[$i] = $counter[$x];
            $counter[$x] = $temp_swap;
 
        }
        for ($i = 0; $i < strlen($data); $i++) {
                        $a = ($a + 1) % 256;
            $j = ($j + $counter[$a]) % 256;
            $temp = $counter[$a];
            $counter[$a] = $counter[$j];
            $counter[$j] = $temp;
            $k = $counter[(($counter[$a] + $counter[$j]) % 256)];
            $Zcipher = ord(substr($data, $i, 1)) ^ $k;
            $Zcrypt .= chr($Zcipher);
        }
        return $Zcrypt;
} 
source: zend code gallery
 
When I encrypt a string that ends in e it shows up as a space in the
database, when I pull it back out of the database, the string is missing the
e. I tried converting the field in the database to a blob and that didn't
work either. My next idea is to add a bin2hex and then a hex2bin:
 
function hex2bin($hexdata) { 
  $bindata=""; 
  
  for ($i=0;$i<strlen($hexdata);$i+=2) { 
   $bindata.=chr(hexdec(substr($hexdata,$i,2))); 
  } 

  return $bindata; 
} 
source: phil at internetprojectmanagers dot com
 
I was hoping to get some feedback if this is a good way to go about this.

Thanks, Mark

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux