Method: PDF::Reader::StandardSecurityHandler#decrypt

Defined in:
lib/pdf/reader/standard_security_handler.rb

#decrypt(buf, ref) ⇒ Object

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



78
79
80
81
82
83
84
85
# File 'lib/pdf/reader/standard_security_handler.rb', line 78

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