Class: PDF::Writer::Object::Encryption

### Home Classes Methods

### In Files

- lib/pdf/writer/object/encryption.rb

### Parent

PDF::Writer::Object

### Methods

- ::new
- #to_s

### Files

- ChangeLog

### Class/Module Index

Quicksearch

- PDF
- PDF::Charts
- PDF::Charts::StdDev
- PDF::Charts::StdDev::Label
- PDF::Charts::StdDev::Marker
- PDF::Charts::StdDev::Scale
- PDF::Math
- PDF::QuickRef
- PDF::SimpleTable
- PDF::SimpleTable::Column
- PDF::SimpleTable::Column::Heading
- PDF::TechBook
- PDF::TechBook::TagTocDots
- PDF::TechBook::TagXref
- PDF::Writer
- PDF::Writer::ARC4
- PDF::Writer::Complex
- PDF::Writer::External
- PDF::Writer::FontMetrics
- PDF::Writer::Graphics
- PDF::Writer::Graphics::ImageInfo
- PDF::Writer::Graphics::ImageInfo::Formats
- PDF::Writer::Graphics::ImageInfo::Type
- PDF::Writer::Lang
- PDF::Writer::Lang::EN
- PDF::Writer::OHash
- PDF::Writer::Object
- PDF::Writer::Object::Action
- PDF::Writer::Object::Annotation
- PDF::Writer::Object::Catalog
- PDF::Writer::Object::Contents
- PDF::Writer::Object::Destination
- PDF::Writer::Object::Encryption
- PDF::Writer::Object::Font
- PDF::Writer::Object::FontDescriptor
- PDF::Writer::Object::FontEncoding
- PDF::Writer::Object::Info
- PDF::Writer::Object::Outline
- PDF::Writer::Object::Outlines
- PDF::Writer::Object::Pages
- PDF::Writer::Object::Procset
- PDF::Writer::Object::ViewerPreferences
- PDF::Writer::OffsetReader
- PDF::Writer::PolygonPoint
- PDF::Writer::State
- PDF::Writer::StateStack
- PDF::Writer::StrokeStyle

No matching classes.

# PDF::Writer::Object::Encryption

Encryption object

### Constants

PAD

### Public Class Methods

new(parent, options) click to toggle source

    # File lib/pdf/writer/object/encryption.rb, line 18
    def initialize(parent, options)
      super(parent)

      @parent.encrypt_obj = self

        # Figure out the additional parameters required.
      @owner  = "#{options[:owner_pass]}#{PAD}"[0...32]
      @user   = "#{options[:user_pass]}#{PAD}"[0...32]
      @perms  = options[:permissions]

      @parent.arc4.prepare(Digest::MD5.hexdigest(@owner)[0...5])

        # Get the 'O' value.
      @owner_info = ARC4.encrypt(@user)
        # Get the 'U' value.
      ukey = @user.dup
      ukey << @owner_info
      ukey << [ @perms, 0xFF, 0xFF, 0xFF ].pack("C*")
      ukey << @parent.file_identifier
      @parent.encryption_key = Digest::MD5.hexdigest(ukey)[0...5]

      @parent.arc4.prepare(@parent.encryption_key)

      @user_info = @parent.arc4.encrypt(PAD)
    end

### Public Instance Methods

to_s() click to toggle source

    # File lib/pdf/writer/object/encryption.rb, line 44
    def to_s
      res = "\n#{@oid} 0 obj\n<<\n/Filter /Standard\n"
      res << "/V 1\n/R 2\n"
      res << "/O (#{PDF::Writer.escape(@owner_info)})\n"
      res << "/U (#{PDF::Writer.escape(@user_info)})\n"
      res << "/P #{(((@perms ^ 255) + 1) * -1)}\n"
      res << ">>\nendobj\n"
      res
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.