Class: PDF::Reader::AesV3SecurityHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/aes_v3_security_handler.rb

Overview

Decrypts data using the AESV3 algorithim defined in the PDF 1.7, Extension Level 3 spec. Requires a decryption key, which is usually generated by PDF::Reader::KeyBuilderV5

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ AesV3SecurityHandler

Returns a new instance of AesV3SecurityHandler.



15
16
17
18
# File 'lib/pdf/reader/aes_v3_security_handler.rb', line 15

def initialize(key)
  @encrypt_key = key
  @cipher = "AES-256-CBC"
end

Instance Method Details

#decrypt(buf, ref) ⇒ Object

7.6.2 General Encryption Algorithm

Algorithm 1: Encryption of data using the RC4 or AES algorithms

used to decrypt RC4/AES encrypted PDF streams (buf)

buf - a string to decrypt ref - a PDF::Reader::Reference for the object to decrypt



29
30
31
32
33
34
35
# File 'lib/pdf/reader/aes_v3_security_handler.rb', line 29

def decrypt( buf, ref )
  cipher = OpenSSL::Cipher.new(@cipher)
  cipher.decrypt
  cipher.key = @encrypt_key.dup
  cipher.iv = buf[0..15]
  cipher.update(buf[16..-1]) + cipher.final
end