英文原文:
Algorithm 3.3 Computing the encryption dictionary’s O (owner password) value
1. Pad or truncate the owner password string as described in step 1 of Algorithm 3.2.
If there is no owner password, use the user password instead. (See implementation
note 17 in Appendix H.)
2. Initialize the MD5 hash function and pass the result of step 1 as input to this function.
3. (Revision 3 only) Do the following 50 times: Take the output from the previous
MD5 hash and pass it as input into a new MD5 hash.
4. Create an RC4 encryption key using the first n bytes of the output from the final
MD5 hash, where n is always 5 for revision 2 but for revision 3 depends on the
value of the encryption dictionary’s Length entry.
5. Pad or truncate the user password string as described in step 1 of Algorithm 3.2.
6. Encrypt the result of step 5, using an RC4 encryption function with the encryption
key obtained in step 4.
7. (Revision 3 only) Do the following 19 times: Take the output from the previous invocation
of the RC4 function and pass it as input to a new invocation of the function;
use an encryption key generated by taking each byte of the encryption key
obtained in step 4 and performing an XOR (exclusive or) operation between that
byte and the single-byte value of the iteration counter (from 1 to 19).
8. Store the output from the final invocation of the RC4 function as the value of the
O entry in the encryption dictionary.
Algorithm 3.2 Computing an encryption key
1. Pad or truncate the password string to exactly 32 bytes. If the password string is
more than 32 bytes long, use only its first 32 bytes; if it is less than 32 bytes long,
pad it by appending the required number of additional bytes from the beginning
of the following padding string:
< 28 BF 4E 5E 4E 75 8A 41 64 00 4E 56 FF FA 01 08
2E 2E 00 B6 D0 68 3E 80 2F 0C A9 FE 64 53 69 7A >
That is, if the password string is n bytes long, append the first 32 − n bytes of the
padding string to the end of the password string. If the password string is empty
(zero-length), meaning there is no user password, substitute the entire padding
string in its place.
2. Initialize the MD5 hash function and pass the result of step 1 as input to this function.
3. Pass the value of the encryption dictionary’s O entry to the MD5 hash function.
(Algorithm 3.3 shows how the O value is computed.)
4. Treat the value of the P entry as an unsigned 4-byte integer and pass these bytes to
the MD5 hash function, low-order byte first.
5. Pass the first element of the file’s file identifier array (the value of the ID entry in
the document’s trailer dictionary; see Table 3.12 on page 68) to the MD5 hash
function and finish the hash.
6. (Revision 3 only) Do the following 50 times: Take the output from the previous
MD5 hash and pass it as input into a new MD5 hash.
7. Set the encryption key to the first n bytes of the output from the final MD5 hash,
where n is always 5 for revision 2 but for revision 3 depends on the value of the encryption
dictionary’s Length entry.