Well, I've tried a few things... and it's getting more than the first line done. It's just that after a while, it stops decoding.....
Here's the class to encode/decode:
function encrypt($decrypted = null, $key = null)
{
if($decrypted !== null)
$this->set_decrypted($decrypted);
if($key !== null)
$this->set_key($key);
if($this->open() === false)
return false;
$key = substr($this->ckey, 0, $this->keySize);
if($this->minit(null, $key, $this->iv) === false)
return false;
$data = pack($this->_packFormat, strlen($this->decrypted)) . $this->decrypted;
$this->encrypted = $this->iv . mcrypt_generic($this->td, $data);
$this->isEncrypted = true;
$this->close();
return $this->encrypted;
}
function decrypt($encrypted = null, $key = null)
{
if($encrypted !== null)
$this->set_encrypted($encrypted);
if($key !== null)
$this->set_key($key);
if($this->open() === false)
return false;
$key = substr($this->ckey, 0, $this->keySize);
$iv = substr($this->encrypted, 0, $this->ivSize);
$encrypted = substr($this->encrypted, $this->ivSize);
if( (strlen($iv) < $this->ivSize) || (strlen($this->ckey) == 0) || (mcrypt_generic_init($this->td, $this->ckey, $iv) < 0) )
{
mcrypt_module_close($this->td);
return false;
}
if($this->minit(null, $key, $iv) === false)
return false;
$this->decrypted = mdecrypt_generic($this->td, $encrypted);
$this->close();
$length = unpack($this->_packFormat, substr($this->decrypted, 0, 4));
$this->decrypted = substr($this->decrypted, 4, $length[1]);
$this->isEncrypted = false;
return $this->decrypted;
}
/*** A ways down in the class ***/
function minit($td = null, $key = null, $iv = null)
{
if($key === null || $iv === null || ($td === null && empty($this->td)))
return false;
if($td === null && !empty($this->td))
$td = $this->td;
if(($err = mcrypt_generic_init($td, $key, $iv)) < 0)
{
$this->close();
return false;
}
return true;
}
No loops are used to encode it. It's done on one line. It's given one large string, and it encodes it. During decode, it decodes either just less than 1 line, or it decodes the first 20 lines, and then stops.....
[EDIT]
Woops... missed the initialization of the buffer... but that still doesn't help. I'm still not getting the true decrypted data.... only a little bit of it....