class HexaPDF::Encryption::StandardSecurityHandler

def compute_user_encryption_key(password)

See: PDF2.0 s7.6.4.3.2 (algorithm 2), PDF2.0 s7.6.4.3.3 (algorithm 2.A (a)-(b),(e))

#compute_owner_encryption_key has to be used instead.
with the user password. If the password is the owner password,
For revision 6 the file encryption key is a string of random bytes that has been encrypted

encrypt or decrypt a file.
For revisions <= 4 this is the *only* way for generating the encryption key needed to

Computes the user encryption key.
def compute_user_encryption_key(password)
  if dict[:R] <= 4
    data = password
    data += dict[:O]
    data << [dict[:P]].pack('V')
    data << document.trailer[:ID][0]
    data << [0xFFFFFFFF].pack('V') if dict[:R] == 4 && !dict[:EncryptMetadata]
    n = key_length
    data = Digest::MD5.digest(data)
    if dict[:R] >= 3
      50.times { data = Digest::MD5.digest(data[0, n]) }
    end
    data[0, n]
  elsif dict[:R] == 6
    key = compute_hash(password, dict[:U][40, 8])
    aes_algorithm.new(key, "\0" * 16, :decrypt).process(dict[:UE])
  end
end