lib/hexapdf/encryption/security_handler.rb in hexapdf-0.14.3 vs lib/hexapdf/encryption/security_handler.rb in hexapdf-0.14.4

- old
+ new

@@ -266,11 +266,11 @@ each_string_in_object(obj.value) do |str| next if str.empty? || (obj.type == :Sig && obj[:Contents].equal?(str)) str.replace(string_algorithm.decrypt(key, str)) end - if obj.kind_of?(HexaPDF::Stream) + if obj.kind_of?(HexaPDF::Stream) && obj.raw_stream.filter[0] != :Crypt unless string_algorithm == stream_algorithm key = object_key(obj.oid, obj.gen, stream_algorithm) end obj.data.stream = EncryptedStreamData.new(obj.raw_stream, key, stream_algorithm) end @@ -298,10 +298,15 @@ result = obj.stream_encoder(source) if result == source && obj.raw_stream.kind_of?(EncryptedStreamData) && obj.raw_stream.key == key && obj.raw_stream.algorithm == stream_algorithm obj.raw_stream.undecrypted_fiber else - stream_algorithm.encryption_fiber(key, result) + filter = obj[:Filter] + if filter == :Crypt || (filter.kind_of?(PDFArray) && filter[0] == :Crypt) + result + else + stream_algorithm.encryption_fiber(key, result) + end end end # Computes the encryption key and sets up the algorithms for encrypting the document based on # the given options, and returns the corresponding encryption dictionary.