diff options
Diffstat (limited to 'pdf-as-legacy/src/test/java/LegacyTest.java')
-rw-r--r-- | pdf-as-legacy/src/test/java/LegacyTest.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/pdf-as-legacy/src/test/java/LegacyTest.java b/pdf-as-legacy/src/test/java/LegacyTest.java new file mode 100644 index 00000000..21d0c3b1 --- /dev/null +++ b/pdf-as-legacy/src/test/java/LegacyTest.java @@ -0,0 +1,60 @@ +import java.io.FileOutputStream; +import java.io.InputStream; +import java.util.Iterator; + +import org.apache.commons.io.IOUtils; + +import at.gv.egiz.pdfas.PdfAsFactory; +import at.gv.egiz.pdfas.api.PdfAs; +import at.gv.egiz.pdfas.api.sign.SignParameters; +import at.gv.egiz.pdfas.api.sign.SignResult; +import at.gv.egiz.pdfas.api.verify.VerifyParameters; +import at.gv.egiz.pdfas.api.verify.VerifyResult; +import at.gv.egiz.pdfas.api.verify.VerifyResults; + +public class LegacyTest { + + public static void main(String[] args) { + try { + PdfAs pdfAS = PdfAsFactory.createPdfAs(); + + SignParameters signParameters = new SignParameters(); + signParameters.setSignatureDevice("bku"); + signParameters.setSignatureProfileId("SIGNATURBLOCK_DE"); + + InputStream is = LegacyTest.class.getResourceAsStream("simple.pdf"); + + byte[] inputData = IOUtils.toByteArray(is); + ByteArrayDataSink bads = new ByteArrayDataSink(); + signParameters.setDocument(new ByteArrayDataSource(inputData)); + signParameters.setOutput(bads); + SignResult result = pdfAS.sign(signParameters); + IOUtils.write(bads.getBytes(), new FileOutputStream("/tmp/test.pdf")); + + System.out.println("Signed @ " + result.getSignaturePosition().toString()); + System.out.println("Signed by " + result.getSignerCertificate().getSubjectDN().getName()); + + VerifyParameters verifyParameters = new VerifyParameters(); + verifyParameters.setDocument(new ByteArrayDataSource(bads.getBytes())); + verifyParameters.setSignatureToVerify(0); + + VerifyResults results = pdfAS.verify(verifyParameters); + + Iterator iter = results.getResults().iterator(); + + while(iter.hasNext()) { + Object obj = iter.next(); + if(obj instanceof VerifyResult) { + VerifyResult vresult = (VerifyResult)obj; + System.out.println("Verified: " + vresult.getValueCheckCode().getCode() + " " + + vresult.getValueCheckCode().getMessage()); + } + } + + } catch (Throwable e) { + System.out.println("ERROR"); + e.printStackTrace(); + } + } + +} |