Documente Academic
Documente Profesional
Documente Cultură
% This file contains the procedures that have to take encryption into
% account when reading a PDF file. It replaces the stub version of this
% file that is shipped with GhostScript. It requires GhostScript 7.01
% or later.
/md5 {
16 string dup /MD5Encode filter dup 4 3 roll writestring closefile
} bind def
/md5_trunk {
md5 0 pdf_key_length getinterval
} bind def
/pdf_padding_string
<28bf4e5e4e758a41 64004e56fffa0108
2e2e00b6d0683e80 2f0ca9fe6453697a>
def
% Algorithm 3.2
/pdf_compute_encryption_key { % <password> pdf_compute_encryption_key <key>
% Step 1.
pdf_pad_key
% Step 2, 3.
Trailer /Encrypt oget dup /O oget
% <padded-key> <encrypt> <O>
% Step 4.
exch /P oget 4 string exch
2 copy 255 and 0 exch put
2 copy -8 bitshift 255 and 1 exch put
2 copy -16 bitshift 255 and 2 exch put
2 copy -24 bitshift 255 and 3 exch put pop
% <padded-key> <O> <P>
% Step 5.
Trailer /ID knownoget { 0 oget } {
()
( **** ID key in the trailer is required for encrypted files.\n)
pdfformaterror
} ifelse
3 { concatstrings } repeat
% We will finish step 5 after possibly including step 6.
% Algorithm 3.4
/pdf_gen_user_password_R2 { % <filekey> pdf_gen_user_password_R2 <U>
% Step 2.
pdf_padding_string exch arc4decode
} bind def
% Algorithm 3.5
/pdf_gen_user_password_R3 { % <filekey> pdf_gen_user_password_R3 <U>
% Step 2.
pdf_padding_string
% Step 3.
Trailer /ID knownoget { 0 oget } {
()
( **** ID key in the trailer is required for encrypted files.\n)
pdfformaterror
} ifelse
concatstrings md5
% Step 4.
1 index arc4decode
% Step 5.
1 1 19 {
2 index pdf_xorbytes arc4decode
} for
exch pop
} bind def
/pdf_gen_user_password { % <password> pdf_gen_user_password <filekey> <U>
% common Step 1 of Algorithms 3.4 and 3.5.
pdf_compute_encryption_key dup
/R oget dup 2 eq {
pop pdf_gen_user_password_R2
} {
dup 3 eq {
pop pdf_gen_user_password_R3
} {
dup 4 eq { % 4 uses the algorithm as 3
pop pdf_gen_user_password_R3
} {
( **** This file uses an unknown standard security handler revision: )
exch =string cvs concatstrings pdfformaterror printProducer
/pdf_check_user_password cvx /undefined signalerror
} ifelse
} ifelse
} ifelse
} bind def
% Algorithm 3.6
/pdf_check_user_password { % <password> pdf_check_user_password <filekey> true
% <password> pdf_check_user_password false
pdf_gen_user_password
% Step 2.
md5_trunk
% Algorithm 3.7
/pdf_check_owner_password { % <password> pdf_check_owner_password <filekey> true
% <password> pdf_check_owner_password false
% Step 1.
pdf_owner_key
% Step 2.
Trailer /Encrypt oget dup /O oget 2 index arc4decode
% <encryption-key> <encrypt-dict> <decrypted-O>
pdf_check_user_password
} bind def
end % pdfdict
.setglobal