Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

I have a PDF file that I want to embed an invisible and fragile digital watermark. What are the suitable algorithms available for this task?

share|improve this question
    
    
@Adnan Firstly, generate the digital watermarking value then hide By using steganography method –  user27889 Jul 6 '13 at 18:11
add comment

1 Answer

The majority of PDF readers will stop reading the PDF data stream upon hitting the %EOF token, and anyway would ignore comments starting with %.

So, it would be perfectly feasible to calculate HMAC-SHA1 and append the resulting hash to the PDF file.

This is not, strictly speaking, a watermark -- but it is invisible and fragile, as requested.

Your resulting PDF file would end in something like

...
startxref
179091
%%EOF
%0xde7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9

from which integrity can be straightforwardly calculated.

With the help of the pdftk tool, you can also be able to uncompress a PDF, manipulate its Adobe Metadata stream (if there is one), and embed inside it a XML HMAC - or even a comment:

3 0 obj
<<
/Subtype /XML
/Length 1381
/Type /Metadata
>>
stream
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<?adobe-xap-filters esc="CRLF"?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9.1-13, framework 1.6'>
...
</x:xmpmeta>
<!-- 0xf7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8 -->
<?xpacket end='w'?>

endstream
endobj

The stream length will be changed; if there is enough slack in the XMP object, you might circumvent this, but there's no need, since pdftk in compress mode will be able to recalculate it and output a valid PDF.

In this latter case, the HMAC information will be compressed and not be directly readable. You will need pdftk (or the iText library, or...) to uncompress the PDF back and recalculate its MAC.

The procedure would be as follows:

  • uncompress the PDF to a stream and attach to the stream
  • read the stream one long line at a time and use it to build the HMAC
  • if a row is found in HMAC format, ignore it for HMAC calculation and store its HMAC value in SavedHMAC
  • on EOF, if checking the HMAC just compare HMAC and SavedHMAC
  • if embedding the HMAC, repeat the uncompress, this time embedding the HMAC row appropriately, then recompress the PDF. This can all be done without writing anything to disk.

You can do the same with a PDF object embedded in the PDF stream, e.g. using the iText library, but this would be much more complicated to be made fragile. PDF objects are largely independent from one another, so you would need to again recourse to something similar to HMAC, this time at object level, and then embed the value as e.g. 100% transparent text, or text outside the page boundaries (I know eBook publishers that employ one or both techniques).

Also with iText, but these are not fragile, are algorithms that modulate spacing of text objects on the page. Most text objects are not aligned to an integer multiple of the page unit:

24.4801 0 Td
[(w)4001.47(atermarking)]TJ
59.7 0 Td
(algorithms)Tj
46.9801 0 Td

and you can easily determine the minimum step that will be visible to the naked eye, e.g. 0.005. Then simply round all text positions, in the order they appear, to the nearest odd multiple of the step, if you want to encode an 1. Or to the nearest even multiple of the step, if you want to encode a 0.

Such a watermark will survive copy and be present independently on each page; with the addition of suitable error recovery (turbo code, Reed-Solomon...), it will also survive the removal or addition of some (not too many, of course...) objects on the page. It is also possible that it will survive printing and be recoverable from a scan of a printed page.

You would do this by implementing a iText RenderListener, whose renderText method would capture the textbox origin and "modulate" it as requested before it being sent to the appropriate PdfCopy.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.