Created
June 25, 2014 23:32
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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