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 889
889:         def compute_encryption_key(password, fileid)
890:           
891:           padded = pad_password(password)
892: 
893:           padded << self.O
894:           padded << [ self.P ].pack("i")
895:           
896:           padded << fileid
897:          
898:           encrypt_metadata = self.EncryptMetadata and not self.EncryptMetadata.false?
899:           padded << "\xFF\xFF\xFF\xFF" if self.R >= 4 and not encrypt_metadata
900:           
901:           key = Digest::MD5.digest(padded)
902: 
903:           50.times { key = Digest::MD5.digest(key[0, self.Length / 8]) } if self.R >= 3
904: 
905:           if self.R == 2
906:             key[0, 5]
907:           elsif self.R >= 3
908:             key[0, self.Length / 8]
909:           end
910:           
911:         end

Checks owner password.

[Source]

     # File sources/parser/encryption.rb, line 953
953:         def is_owner_password?(pass, fileid)
954:         
955:           key = compute_owner_encryption_key(pass)
956:           
957:           if self.R == 2
958:             user_password = ARC4.decrypt(key, self.O)
959:           elsif self.R >= 3
960:             user_password = ARC4.decrypt(xor(key, 19), self.O)
961:             19.times { |i| user_password = ARC4.decrypt(xor(key, 18-i), user_password) }
962:           end
963:           
964:           is_user_password?(user_password, fileid)
965:         
966:         end

Checks user password.

[Source]

     # File sources/parser/encryption.rb, line 940
940:         def is_user_password?(pass, fileid)
941:           
942:           if self.R == 2 
943:             compute_user_password(pass, fileid) == self.U
944:           elsif self.R >= 3
945:             compute_user_password(pass, fileid)[0, 16] == self.U[0, 16]
946:           end
947:           
948:         end

Set owner password.

[Source]

     # File sources/parser/encryption.rb, line 916
916:         def set_owner_password(userpassword, ownerpassword = nil)
917:           
918:           key = compute_owner_encryption_key(userpassword, ownerpassword)
919:           upadded = pad_password(userpassword)
920:           
921:           owner_key = ARC4.encrypt(key, upadded)
922:           19.times { |i| owner_key = ARC4.encrypt(xor(key,i+1), owner_key) } if self.R >= 3
923:           
924:           self.O = owner_key
925:           
926:         end

Set user password.

[Source]

     # File sources/parser/encryption.rb, line 931
931:         def set_user_password(userpassword, fileid = nil)
932:           
933:           self.U = compute_user_password(userpassword, fileid)
934:         
935:         end

[Validate]