title: Verification of pdf integrity fail
body: <p>I'm trying to verify via bash commands the integrity of a pdf file.</p>
  
  <p>Using dd I extracted the signedContent and the pkcs7 detached object of the pdf.</p>
  
  <p>Then I decoded the pkcs via</p>
  
  <pre><code>xxd -r -p pkcs7_extracted &gt; pkcs7_extracted.bin
  
  openssl asn1parse -inform DER &lt;pkcs7_extracted.bin &gt;pkcs7_extracted_decoded
  </code></pre>
  
  <p>from the decoded pkcs7 I got some useful information as</p>
  
  <pre><code> 0:d=0  hl=4 l=5498 cons: SEQUENCE         
   4:d=1  hl=2 l=   9 prim: OBJECT            :pkcs7-signedData
   15:d=1  hl=4 l=5483 cons: cont [ 0 ]        
   19:d=2  hl=4 l=5479 cons: SEQUENCE          
   23:d=3  hl=2 l=   1 prim: INTEGER           :01
   26:d=3  hl=2 l=  15 cons: SET               
   28:d=4  hl=2 l=  13 cons: SEQUENCE          
   30:d=5  hl=2 l=   9 prim: OBJECT            :sha256
   41:d=5  hl=2 l=   0 prim: NULL              
   43:d=3  hl=2 l=  11 cons: SEQUENCE          
   ...
   5154:d=7  hl=2 l=   9 prim: OBJECT            :contentType
   5165:d=7  hl=2 l=  11 cons: SET               
   5167:d=8  hl=2 l=   9 prim: OBJECT            :pkcs7-data
   5178:d=6  hl=2 l=  47 cons: SEQUENCE          
   5180:d=7  hl=2 l=   9 prim: OBJECT            :messageDigest
   5191:d=7  hl=2 l=  34 cons: SET               
   5193:d=8  hl=2 l=  32 prim: OCTET STRING      [HEX DUMP]:18B399D208A08815DDF23C93B1B63B13757A6AA24B1932569D7A69D0DB3A34C2
   5227:d=5  hl=2 l=  13 cons: SEQUENCE          
   5229:d=6  hl=2 l=   9 prim: OBJECT            :sha256WithRSAEncryption
   5240:d=6  hl=2 l=   0 prim: NULL              
   5242:d=5  hl=4 l= 256 prim: OCTET STRING      [HEX DUMP]:8F4B21914173EC57E6B0533BB5E04FB7054F23AC299C1BDBF589ED164A3EABB611727BE9117AAC3161D9C18DCA08BD113DD3AA90E5922009FA12BA59E7F6587E81CD79BDED09F862C2C76F35D950926F1A31A3DCCE999A52DCE0C7F67D081E81A44397E8AF96A1051B8E51F2E2271221B06D05C9895E1846B1DBE02B558F5B9EF97C7EB0FF9A7C71A9764D5E205900818F07E82027D79D3F9A5AA72B3A0CF131F1B890D0BCBF3C4DD8A0229FABE15F6C2CA0CE079EB925B3998A1A6190596A88D8F07C1C12B8750636E69108E30E643A653B285A400080C9C5590C112451F6D69BAFC2686D6F1107B37A5DB36B9F797C49E61D4B44E62E17DD541778DE763AC5
   5502:d=0  hl=2 l=   0 prim: EOC              
  </code></pre>
  
  <p>in particular I notice that the messageDigest field is equal to the calculated digest of the signedContent obtained using the ByteRange.</p>
  
  <p>I've so extracted the encrypted hash, decrypted it with my publickey and decoded again with asn1 command.</p>
  
  <pre><code>dd if=pkcs7_extracted.bin of=extracted.sign.bin bs=1 skip=$[ 5242 + 4 ] count=256
  
  #decrypt
  
  openssl rsautl -verify -pubin -inkey publickey.pem &lt; extracted.sign.bin &gt; verified.bin
  
  #decode of result
  openssl asn1parse -inform der -in verified.bin
  </code></pre>
  
  <p>the result is this object</p>
  
  <pre><code>0:d=0  hl=2 l=  49 cons: SEQUENCE          
  2:d=1  hl=2 l=  13 cons: SEQUENCE          
  4:d=2  hl=2 l=   9 prim: OBJECT            :sha256
  15:d=2  hl=2 l=   0 prim: NULL              
  17:d=1  hl=2 l=  32 prim: OCTET STRING      [HEX DUMP]:EBAA31519CD0CCA793FEC34AA6BDD8DFA5E4D5F63BA4711F6C8ECE5D20FEF393
  </code></pre>
  
  <p>I'm pretty sure decryption worked since the object is correctly decoded and as I expected contains a sha256 object but as you can see the digest value is <strong>different</strong>...</p>
  
  <p>Am I looking in the wrong place? I've no more idea how to verify the integrity.</p>
  
  <p>In addition Acrobat of course validate the integrity of the document for this signature.</p>
  
  <p>thanks in advance!</p>