Method: Origami::Encryption::Standard::Dictionary#compute_user_encryption_key

Defined in:
lib/origami/encryption.rb

#compute_user_encryption_key(user_password, file_id) ⇒ Object

Computes the key that will be used to encrypt/decrypt the document contents with user password. Called at all revisions.



792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
# File 'lib/origami/encryption.rb', line 792

def compute_user_encryption_key(user_password, file_id)
    return compute_legacy_user_encryption_key(user_password, file_id) if self.R < 5

    passwd = password_to_utf8(user_password)

    uks = self.U[40, 8]

    if self.R == 5
        ukey = Digest::SHA256.digest(passwd + uks)
    else
        ukey = compute_hardened_hash(passwd, uks)
    end

    iv = ::Array.new(AES::BLOCKSIZE, 0).pack("C*")
    AES.new(ukey, nil, false).decrypt(iv + self.UE.value)
end