I'm hoping I can get some help on a project I'm working on. Using Adobe's specs on PDFs, I'm trying to decrypt a file (not decode it. I have achieved that already), but I think I'm having some serious issues with the encryption key I'm generating.
Here's a link to the specs document:http://www.adobe.com/devnet/acrobat/pdf ... 0_2008.pdf The algorithm starts on PDF page 69.
Here's the code I have:
Code: Select all
function get_encryption_key($user_pass, $params, $id)
{
//print $id;
$padding = "\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";
$n = $params['R'] > 2 ? $params['Length']/8 : 5;
$input = substr($user_pass.$padding, 0, 32); //step a and b.
$input .= $params['O']; // step c
$input .= pack('V*', $params['P']); // step d
$input .= $id; // step e
$key = md5($input, true); // step g
if($params['R'] > 2)
{
for($i = 0; $i < 50; $i++)
{
$key = md5(substr($key, 0, $n), true); // step h.
}
}
return substr($key, 0, $n); // step i.
}Thanks so much.