|
Posted by "Mark Steudel" on 12/19/05 20:56
I have the following encryption function. And what I wanted to know is, Do I
need to convert this to hex before storing this in a mysql database? Or
could I store it into a blob and be fine?
// from zend code gallery
function RC4($keyfile, $data) { //ecncrypt $data with the key in $keyfile
with an rc4 algorithm
$pwd = implode('', file($keyfile));
$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;
}
[Back to original message]
|