Skip to content

Commit

Permalink
fixed special char issue in doc info by printing hex strings instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ole1986 committed Jun 26, 2017
1 parent 51ab740 commit a478f54
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
5 changes: 5 additions & 0 deletions data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Note that this document was generated using the demo script 'readme.php' which c

1<Changelog>


3<0.12.38>

- finally fixed special char issue when encrypting documents (document info - #70)

3<0.12.37>

- fixed issue #70
Expand Down
Binary file modified readme.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion readme.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function dots($info){
// this code has been modified to use ezpdf.

$project_url = "https://github.com/rospdf/";
$project_version = "0.12.37";
$project_version = "0.12.38";

$pdf = new Creport('a4','portrait', 'none', null);
// to test on windows xampp
Expand Down
71 changes: 33 additions & 38 deletions src/Cpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function __construct($pageSize = array(0, 0, 612, 792), $isUnicode = fals
{
$this->isUnicode = $isUnicode;
// set the hardcoded encryption pad
$this->encryptionPad = chr(0x28).chr(0xBF).chr(0x4E).chr(0x5E).chr(0x4E).chr(0x75).chr(0x8A).chr(0x41).chr(0x64).chr(0x00).chr(0x4E).chr(0x56).chr(0xFF).chr(0xFA).chr(0x01).chr(0x08).chr(0x2E).chr(0x2E).chr(0x00).chr(0xB6).chr(0xD0).chr(0x68).chr(0x3E).chr(0x80).chr(0x2F).chr(0x0C).chr(0xA9).chr(0xFE).chr(0x64).chr(0x53).chr(0x69).chr(0x7A);
$this->encryptionPad = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";

$this->newDocument($pageSize);

Expand Down Expand Up @@ -1138,7 +1138,7 @@ private function o_info($id, $action, $options = '')
case 'new':
$this->infoObject = $id;
$date = 'D:'.date('YmdHis')."-00'00";
$this->objects[$id] = array('t' => 'info', 'info' => array('Creator' => 'R&OS php pdf class, http://pdf-php.sf.net/', 'CreationDate' => $date));
$this->objects[$id] = array('t' => 'info', 'info' => array('Creator' => 'R&OS PDF php class', 'CreationDate' => $date));
break;
case 'Title':
case 'Author':
Expand All @@ -1157,13 +1157,13 @@ private function o_info($id, $action, $options = '')
}
$res = "\n".$id." 0 obj\n<< ";
foreach ($o['info'] as $k => $v) {
$res .= '/'.$k.' (';
$res .= '/'.$k.' ';
if ($this->encryptionMode > 0) {
$res .= $this->ARC4($this->filterText($v, true, false));
$res .= '<' . $this->strToHex($this->ARC4($v)) . '> ';
} else {
$res .= $this->filterText($v, true, false);
$res .= '(' . $this->filterText($v, true, false) . ') ';
}
$res .= ') ';
//$res .= ') ';
}
$res .= ">>\nendobj";

Expand Down Expand Up @@ -1668,10 +1668,7 @@ private function hexToStr($hex)
*/
private function md5_16($string)
{
$tmp = md5($string);
$out = pack('H*', $tmp);

return $out;
return pack('H*', md5($string));
}

/**
Expand Down Expand Up @@ -1703,44 +1700,42 @@ private function ARC4_init($key = '')
if (strlen($key) == 0) {
return;
}
$k = '';
while (strlen($k) < 256) {
$k .= $key;
}
$k = substr($k, 0, 256);
for ($i = 0; $i < 256; ++$i) {
$this->arc4 .= chr($i);

$s = array();
for ($i = 0; $i < 256; $i++) {
$s[$i] = $i;
}

$j = 0;
for ($i = 0; $i < 256; ++$i) {
$t = $this->arc4[$i];
$j = ($j + ord($t) + ord($k[$i])) % 256;
$this->arc4[$i] = $this->arc4[$j];
$this->arc4[$j] = $t;
for ($i = 0; $i < 256; $i++) {
$j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
}

$this->arc4 = $s;
}

/**
* ARC4 encrypt a text string.
*/
private function ARC4($text)
{
$len = strlen($text);
$a = 0;
$b = 0;
$c = $this->arc4;
$out = '';
for ($i = 0; $i < $len; ++$i) {
$a = ($a + 1) % 256;
$t = $c[$a];
$b = ($b + ord($t)) % 256;
$c[$a] = $c[$b];
$c[$b] = $t;
$k = ord($c[(ord($c[$a]) + ord($c[$b])) % 256]);
$out .= chr(ord($text[$i]) ^ $k);
}

return $out;
$i = 0;
$j = 0;
$s = $this->arc4;
$res = '';
for ($y = 0; $y < strlen($text); $y++) {
$i = ($i + 1) % 256;
$j = ($j + $s[$i]) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
$res .= $text[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
}

return $res;
}

public function addComment($title, $text, $x, $y)
Expand Down

0 comments on commit a478f54

Please sign in to comment.