RE: [PHP] unsupported binary characters in database,

2006-02-13 Thread Mark Steudel
 I found another way to deal with this. And that's to run the encrypted
string through base64_encode before inserting into database and running
base64_decode when pulling it out of the database.

Mark

-Original Message-
From: Mark Steudel [mailto:[EMAIL PROTECTED] 
Sent: Sunday, February 12, 2006 11:18 AM
To: 'Webmaster'; php-general@lists.php.net
Subject: RE: [PHP] unsupported binary characters in database,

Hmmm ... I guess that's an idea. Any other ways of dealing with this?  

-Original Message-
From: Webmaster [mailto:[EMAIL PROTECTED]
Sent: Saturday, February 11, 2006 6:06 PM
To: Mark Steudel
Subject: Re: [PHP] unsupported binary characters in database,

Mark Steudel wrote:
 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;$istrlen($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

   
Just add a different letter to the end of the string.  So long as it isn't
e it should be ok yeah?

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

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



RE: [PHP] unsupported binary characters in database,

2006-02-12 Thread Mark Steudel
Hmmm ... I guess that's an idea. Any other ways of dealing with this?  

-Original Message-
From: Webmaster [mailto:[EMAIL PROTECTED] 
Sent: Saturday, February 11, 2006 6:06 PM
To: Mark Steudel
Subject: Re: [PHP] unsupported binary characters in database,

Mark Steudel wrote:
 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;$istrlen($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

   
Just add a different letter to the end of the string.  So long as it isn't
e it should be ok yeah?

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