Skip to content

Instantly share code, notes, and snippets.

@kwart
Created June 25, 2014 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwart/5c2a2653e22ca1d3f467 to your computer and use it in GitHub Desktop.
Save kwart/5c2a2653e22ca1d3f467 to your computer and use it in GitHub Desktop.
TSA hash algorithm used in a signed PDF (jsignpdf-itxt 1.5.5)
import java.util.List;
import net.sf.jsignpdf.utils.PdfUtils;
import org.bouncycastle.tsp.TimeStampToken;
import com.lowagie.text.pdf.AcroFields;
import com.lowagie.text.pdf.PdfPKCS7;
import com.lowagie.text.pdf.PdfReader;
public class TsaHashName {
public static void main(String[] args) throws Exception {
PdfReader pr = PdfUtils.getPdfReader("test_signed.pdf", null);
final AcroFields tmpAcroFields = pr.getAcroFields();
final List<String> tmpNames = tmpAcroFields.getSignatureNames();
final int lastSignatureIdx = tmpNames.size() - 1;
for (int i = lastSignatureIdx; i >= 0; i--) {
final String name = tmpNames.get(i);
System.out.println("Signature: " + name);
final PdfPKCS7 pk = tmpAcroFields.verifySignature(name);
final TimeStampToken tst = pk.getTimeStampToken();
if (tst != null) {
System.out.println("HashAlgorithm: "
+ PdfPKCS7.getDigestStdName(tst.getTimeStampInfo()
.getHashAlgorithm().getAlgorithm().getId()));
}
}
pr.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment