aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-legacy/src/test/java/LegacyTest.java
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-01-21 09:57:16 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-01-21 09:57:16 +0100
commit2436aa273f00dafb465c2342ea8e7297898915d2 (patch)
tree27cf115b4ec6d36f84b01b50acc403cf31b3ab6b /pdf-as-legacy/src/test/java/LegacyTest.java
parent8d801ab37834b0f11c6a16c240d77da71a6ab816 (diff)
downloadpdf-as-4-2436aa273f00dafb465c2342ea8e7297898915d2.tar.gz
pdf-as-4-2436aa273f00dafb465c2342ea8e7297898915d2.tar.bz2
pdf-as-4-2436aa273f00dafb465c2342ea8e7297898915d2.zip
Implementations for pdf-as-web and pdf-as-legacy
Diffstat (limited to 'pdf-as-legacy/src/test/java/LegacyTest.java')
-rw-r--r--pdf-as-legacy/src/test/java/LegacyTest.java60
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();
+ }
+ }
+
+}