Python добавление метки времени в файл PDF - PullRequest
0 голосов
/ 01 февраля 2020

Я пытаюсь установить временную метку в файле PDF следующим образом:

import hashlib
import datetime
import time

infn = 'a.pdf'

hash = hashlib.sha256()
with open(infn, 'rb') as infile:
    chunk = 0
    while chunk != b'':
        chunk = infile.read(1024)    # Read 1024 bytes at a time
        hash.update(chunk)

# Simulate sending the hash to a TSA and get the timestamped hash
ts = int(time.time())
stamp = datetime.datetime.fromtimestamp(ts)
hash.update(str(stamp).encode('utf-8'))
print(hash.hexdigest())

# Add the timestamped hash to the original file 'a.pdf,' how?
outfn = 'a-stamped.pdf'

У меня есть следующие вопросы:

  • Есть ли стандартный размер чанка (сейчас я выбираю 1024 )?
  • Как добавить метку времени ha sh в исходный файл PDF?
...