... and finally you will create your own implementation of (un)serialize() pair of functions. But why
You will have a pair of functions which do eventually the same thing as the PHP native ones...
Moderator: General Moderators
Code: Select all
$cookie2 = 'audio.0/backgroundimages./browserpatch.1/chatroom.0/connection.0/css3.0/cursors.0/dhtmleffects./dtd.1/ieccss.1/initialfocus.content/keyboardlayout.designer/mediatype./personality.0/powerkeys.0/sounds.0/theme.classic';
list($audio, $backgroundimages, $browserpatch, $chatroom, $connection, $css3, $cursors, $dhtmleffects, $dtd, $ieccss, $keyboardlayout, $mediatype, $personality, $powerkeys, $sounds, $theme) = split('[/.-]', $cookie2);Code: Select all
class SecureCookieStorage
{
function SecureCookieStorage($namespace, $salt)
{
$this->salt = $salt;
$this->namespace = $namespace;
$this->expire = 29000;
$this->encrypt_algorithm = 'sha1';
}
function write($data)
{
if (!setcookie($this->namespace, ($data = gzdeflate(serialize($data))), time() + $this->expire, '/'))
return false;
if (!setcookie($this->namespace.'_hmac', $this->_hmac($data), time() + $this->expire, '/'))
return false;
return true;
}
function read()
{
if ($this->_hmac($_COOKIE[$this->namespace]) != $_COOKIE[$this->namespace.'_hmac'])
return false;
if (!($data = gzinflate($_COOKIE[$this->namespace])))
return false;
if (!($data = unserialize($data)))
return false;
return $data;
}
function _hmac($data)
{
/* md5 and sha1 only */
$this->encrypt_algorithm = strtolower($this->encrypt_algorithm);
$map = array('md5'=>'H32','sha1'=>'H40');
if (strlen($this->salt) > 64)
$this->salt = pack($map[$this->encrypt_algorithm], $this->encrypt_algorithm($this->salt));
if (strlen($this->salt) < 64)
$this->salt = str_pad($this->salt, 64, chr(0));
$ipad = substr($this->salt, 0, 64) ^ str_repeat(chr(0x36), 64);
$opad = substr($this->salt, 0, 64) ^ str_repeat(chr(0x5C), 64);
return($this->encrypt_algorithm($opad.pack($map[$this->encrypt_algorithm], $this->encrypt_algorithm($ipad.$data))));
}
}
JAB Creations wrote:Whoa...that is just insane code. I don't want to be rude or disappoint you in any way but while that may look like gold to you right now at my level it looks like a big hairy bug that says, 'Go ahead, just put your hand near my mouth!'