class PDF::Reader::Rc4SecurityHandler


a decryption key, which is usually generated by PDF::Reader::StandardKeyBuilder
Decrypts data using the RC4 algorithim defined in the PDF spec. Requires

def decrypt( buf, ref )


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

version <=3 or (version == 4 and CFM == V2)

Algorithm 1: Encryption of data using the RC4 algorithm

#7.6.2 General Encryption Algorithm
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

def initialize(key)

def initialize(key)
  @encrypt_key = key
end