PDFdev is a service provided by PDFzone.com | http://www.pdfzone.com
_____________________________________________________________
To quote the relevant spec directly:
1. Obtain the object number and generation number from the object identifier
of the
string or stream to be encrypted (see Section 3.2.9, "Indirect Objects"). If
the
string is a direct object, use the identifier of the indirect object
containing it.
2. Treating the object number and generation number as binary integers,
extend the
original n-byte encryption key to n + 5 bytes by appending the low-order 3
bytes
of the object number and the low-order 2 bytes of the generation number in
that
order, low-order byte first. (n is 5 unless the value of V in the encryption
dictionary
is greater than 1, in which case n is the value of Length divided by 8.)
3. Initialize the MD5 hash function and pass the result of step 2 as input
to this function.
4. Use the first (n + 5) bytes, up to a maximum of 16, of the output from
the MD5
hash as the key for the RC4 encryption function, along with the string or
stream
data to be encrypted. The output is the encrypted data to be stored in the
PDF file.
So it looks like your doing step 2 wrong.
The 5-byte pad should be:
low order 3 bytes from obj num: 00 00 15 (that was 20 decimal, right?)
low order 2 bytes from gen num: 00 00
result:
00 00 15 00 00
You'd then generate an MD5 hash of "8d 46 6d 60 c5 00 00 15 00 00", and
continue straight on till morning.
--Mark Storer
Software Engineer
Cardiff Software
#include <disclaimer>
typdef std::disclaimer<Cardiff> Discard;
>
> Okay. I'm at the point where I'm generating a valid User
> and Owner entries
> in my encryption dictionary. These have been verified against my test
> document. Now I need to determine the Encryption Key for my
> data stream.
>
> Could someone please verify the steps that I'm taking to try
> and encrypt my
> text stream.
>
> Taking the info from PDF Spec 1.4 and Algorithm 3.1, I need to:
> 1. Determine my object and Gen numbers (eg: object = 20 and gen =0)
> 2. Take my original Encryption Key (which was previously determined in
> Algorithm 3.2) and append low-order the low order bytes of my
> object and Gen
> numbers. Assuming my Original Encryption key is "8d 46 6d 60
> c5", I now
> append the combo of Object + Gen which is "30 32 30 30 30".
> 3. Run the MD5 hash with this 10-byte key, which is now "8d
> 46 6d 60 c5 30
> 32 30 30 30". From the MD5 hash I get a 16 Byte value of:
> 46 fc b8 80 ca b5 9e 15 c9 cf 78 e3 6f 83 67 0c
> 4. I take the first 10-bytes of the 16 Byte value (46 fc b8
> 80 ca b5 9e 15
> c9 cf ) and use this plus my text as the input to my RC4.
> example call: run rc4 ("Hello World",<16-bytes>)
> I use the output of this call as my text stream.
>
>
> TIA,
> Gordon
To change your subscription:
http://www.pdfzone.com/discussions/lists-pdfdev.html