Class: PDF::Reader::StandardSecurityHandler

### Home Classes Methods

### In Files

- lib/pdf/reader/standard_security_handler.rb

### Parent

Object

### Methods

- ::new
- #decrypt

### Files

- MIT-LICENSE
- README.rdoc
- TODO
- mac_expert.txt
- mac_roman.txt
- pdf_doc.txt
- standard.txt
- symbol.txt
- win_ansi.txt
- zapf_dingbats.txt
- glyphlist.txt

### Class/Module Index

Quicksearch

- PDF
- PDF::Reader
- PDF::Reader::Buffer
- PDF::Reader::CidWidths
- PDF::Reader::EncryptedPDFError
- PDF::Reader::Filter
- PDF::Reader::Filter::Ascii85
- PDF::Reader::Filter::AsciiHex
- PDF::Reader::Filter::Depredict
- PDF::Reader::Filter::Flate
- PDF::Reader::Filter::Lzw
- PDF::Reader::Filter::Null
- PDF::Reader::Filter::RunLength
- PDF::Reader::Font
- PDF::Reader::FontDescriptor
- PDF::Reader::FormXObject
- PDF::Reader::InvalidObjectError
- PDF::Reader::MalformedPDFError
- PDF::Reader::ObjectCache
- PDF::Reader::ObjectHash
- PDF::Reader::PageLayout
- PDF::Reader::PageState
- PDF::Reader::PageTextReceiver
- PDF::Reader::Parser
- PDF::Reader::PrintReceiver
- PDF::Reader::Reference
- PDF::Reader::RegisterReceiver
- PDF::Reader::ResourceMethods
- PDF::Reader::StandardSecurityHandler
- PDF::Reader::Stream
- PDF::Reader::SynchronizedCache
- PDF::Reader::TextReceiver
- PDF::Reader::TextRun
- PDF::Reader::TransformationMatrix
- PDF::Reader::UnsupportedFeatureError
- PDF::Reader::WidthCalculator
- PDF::Reader::WidthCalculator::BuiltIn
- PDF::Reader::WidthCalculator::Composite
- PDF::Reader::WidthCalculator::TrueType
- PDF::Reader::WidthCalculator::TypeOneOrThree
- PDF::Reader::WidthCalculator::TypeZero
- PDF::Reader::XRef
- AFM
- AFM::Font

No matching classes.

# 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.