Class Origami::Encryption::Standard::Dictionary
In: sources/parser/encryption.rb
Parent: EncryptionDictionary

Class defining a standard encryption dictionary.

Methods

Constants

O = owner_key
U = compute_user_password(userpassword, fileid)

Public Instance methods

Computes the key that will be used to encrypt/decrypt the document.

[Source]

     # File sources/parser/encryption.rb, line 956
956:         def compute_encryption_key(password, fileid)
957:           
958:           padded = pad_password(password)
959: 
960:           padded << self.O
961:           padded << [ self.P ].pack("i")
962:           
963:           padded << fileid
964:           
965:           encrypt_metadata = self.EncryptMetadata != false
966:           padded << "\xFF\xFF\xFF\xFF" if self.R >= 4 and not encrypt_metadata
967: 
968:           key = Digest::MD5.digest(padded)
969: 
970:           50.times { key = Digest::MD5.digest(key[0, self.Length / 8]) } if self.R >= 3
971: 
972:           if self.R == 2
973:             key[0, 5]
974:           elsif self.R >= 3
975:             key[0, self.Length / 8]
976:           end
977:            
978:         end

Checks owner password.

[Source]

      # File sources/parser/encryption.rb, line 1018
1018:         def is_owner_password?(pass, fileid)
1019:         
1020:           key = compute_owner_encryption_key(pass)
1021: 
1022:           if self.R == 2
1023:             user_password = ARC4.decrypt(key, self.O)
1024:           elsif self.R >= 3
1025:             user_password = ARC4.decrypt(xor(key, 19), self.O)
1026:             19.times { |i| user_password = ARC4.decrypt(xor(key, 18-i), user_password) }
1027:           end
1028:           
1029:           is_user_password?(user_password, fileid)
1030:         end

Checks user password.

[Source]

      # File sources/parser/encryption.rb, line 1005
1005:         def is_user_password?(pass, fileid)
1006:           
1007:           if self.R == 2 
1008:             compute_user_password(pass, fileid) == self.U
1009:           elsif self.R >= 3
1010:             compute_user_password(pass, fileid)[0, 16] == self.U[0, 16]
1011:           end
1012:           
1013:         end

Set owner password.

[Source]

     # File sources/parser/encryption.rb, line 983
983:         def set_owner_password(userpassword, ownerpassword = nil)
984:           
985:           key = compute_owner_encryption_key(userpassword, ownerpassword)
986:           upadded = pad_password(userpassword)
987:           
988:           owner_key = ARC4.encrypt(key, upadded)
989:           19.times { |i| owner_key = ARC4.encrypt(xor(key,i+1), owner_key) } if self.R >= 3
990:           
991:           self.O = owner_key
992:         end

Set user password.

[Source]

      # File sources/parser/encryption.rb, line 997
 997:         def set_user_password(userpassword, fileid = nil)
 998:           
 999:           self.U = compute_user_password(userpassword, fileid)
1000:         end

[Validate]