Parent

Methods

PDF::Reader::StandardSecurityHandler

class creates interface to encrypt dictionary for use in Decrypt

Constants

PassPadBytes
7.6.3.3 Encryption Key Algorithm (pp61)

needs a document's user password to build a key for decrypting an encrypted PDF document

Attributes

crypt_filter[R]
embedded_file_filter[R]
encrypt_key[R]
file_id[R]
filter[R]
key_length[R]
owner_key[R]
password[R]
permissions[R]
revision[R]
stream_filter[R]
string_filter[R]
subFilter[R]
user_key[R]
version[R]

Public Class Methods

new( enc, file_id, password ) click to toggle source
# File lib/pdf/reader/standard_security_handler.rb, line 49
def initialize( enc, file_id, password )
  @filter        = enc[:Filter]
  @subFilter     = enc[:SubFilter]
  @version       = enc[:V].to_i
  @key_length    = enc[:Length].to_i/8
  @crypt_filter  = enc[:CF]
  @stream_filter = enc[:StmF]
  @string_filter = enc[:StrF]
  @revision      = enc[:R].to_i
  @owner_key     = enc[:O]
  @user_key      = enc[:U]
  @permissions   = enc[:P].to_i
  @embedded_file_filter = enc[:EFF]

  @encryptMeta   = enc.has_key?(:EncryptMetadata)? enc[:EncryptMetadata].to_s == "true" : true;

  @file_id       = file_id.first

  @encrypt_key   = build_standard_key(password)
end

Public Instance Methods

decrypt( buf, ref ) click to toggle source

7.6.2 General Encryption Algorithm

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

used to decrypt RC4 encrypted PDF streams (buf)

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

# File lib/pdf/reader/standard_security_handler.rb, line 79
def decrypt( buf, ref )
  objKey = @encrypt_key.dup
  (0..2).each { |e| objKey << (ref.id >> e*8 & 0xFF ) }
  (0..1).each { |e| objKey << (ref.gen >> e*8 & 0xFF ) }
  length = objKey.length < 16 ? objKey.length : 16
  rc4 = RC4.new( Digest::MD5.digest(objKey)[(0...length)] )
  rc4.decrypt(buf)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.