class PDF::Writer::Object::Encryption
Encryption
object
Constants
- PAD
Public Class Methods
new(parent, options)
click to toggle source
Calls superclass method
PDF::Writer::Object::new
# File lib/pdf/writer/object/encryption.rb 18 def initialize(parent, options) 19 super(parent) 20 21 @parent.encrypt_obj = self 22 23 # Figure out the additional parameters required. 24 @owner = "#{options[:owner_pass]}#{PAD}"[0...32] 25 @user = "#{options[:user_pass]}#{PAD}"[0...32] 26 @perms = options[:permissions] 27 28 @parent.arc4.prepare(Digest::MD5.hexdigest(@owner)[0...5]) 29 30 # Get the 'O' value. 31 @owner_info = ARC4.encrypt(@user) 32 # Get the 'U' value. 33 ukey = @user.dup 34 ukey << @owner_info 35 ukey << [ @perms, 0xFF, 0xFF, 0xFF ].pack("C*") 36 ukey << @parent.file_identifier 37 @parent.encryption_key = Digest::MD5.hexdigest(ukey)[0...5] 38 39 @parent.arc4.prepare(@parent.encryption_key) 40 41 @user_info = @parent.arc4.encrypt(PAD) 42 end
Public Instance Methods
to_s()
click to toggle source
# File lib/pdf/writer/object/encryption.rb 44 def to_s 45 res = "\n#{@oid} 0 obj\n<<\n/Filter /Standard\n" 46 res << "/V 1\n/R 2\n" 47 res << "/O (#{PDF::Writer.escape(@owner_info)})\n" 48 res << "/U (#{PDF::Writer.escape(@user_info)})\n" 49 res << "/P #{(((@perms ^ 255) + 1) * -1)}\n" 50 res << ">>\nendobj\n" 51 res 52 end