Class: CombinePDF::PDFDecrypt

Inherits:
Object
  • Object
show all
Defined in:
lib/combine_pdf/combine_pdf_decrypt.rb

Overview

This is an internal class. you don’t need it.

Instance Method Summary collapse

Constructor Details

#initialize(objects = [], root_dictionary = {}) ⇒ PDFDecrypt

make a new Decrypt object. requires:

objects

an array containing the encrypted objects.

root_dictionary

the root PDF dictionary, containing the Encrypt dictionary.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/combine_pdf/combine_pdf_decrypt.rb', line 22

def initialize objects=[], root_dictionary = {}
  @objects = objects
  @encryption_dictionary = root_dictionary[:Encrypt]
  raise "Cannot decrypt an encrypted file without an encryption dictionary!" unless @encryption_dictionary
  @root_dictionary = root_dictionary
  @padding_key = [ 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
          0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
          0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
          0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A ]
  @key_crypt_first_iv_store = nil
  @encryption_iv = nil
  PDFOperations.change_references_to_actual_values @objects, @encryption_dictionary
end

Instance Method Details

#decryptObject

call this to start the decryption.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/combine_pdf/combine_pdf_decrypt.rb', line 37

def decrypt
  raise_encrypted_error @encryption_dictionary unless @encryption_dictionary[:Filter] == :Standard
  @key = set_general_key
  case @encryption_dictionary[:V]
  when 1,2
    warn "trying to decrypt with RC4."
    # raise_encrypted_error
    _perform_decrypt_proc_ @objects, self.method(:decrypt_RC4)
  else
    raise_encrypted_error
  end
  #rebuild stream lengths?
  @objects
end