class Writer::Object::Encryption
Encryption object
Constants
- PAD
Public Class Methods
new(parent, options)
click to toggle source
Calls superclass method
# 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