summaryrefslogtreecommitdiff
path: root/eaaf_modules/eaaf_module_moa-sig/src/test/java/console/PdfSigDecoder.java
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-04-06 09:54:23 +0200
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-04-06 09:54:23 +0200
commit68e96ea339f58efb772b4ad77f617347aeb1ce71 (patch)
tree57c285f61a2fae2fc8bf55f6970b76d5af520778 /eaaf_modules/eaaf_module_moa-sig/src/test/java/console/PdfSigDecoder.java
parent3b5f84e413694270f54e5f47d8130276b02a463a (diff)
downloadEAAF-Components-68e96ea339f58efb772b4ad77f617347aeb1ce71.tar.gz
EAAF-Components-68e96ea339f58efb772b4ad77f617347aeb1ce71.tar.bz2
EAAF-Components-68e96ea339f58efb772b4ad77f617347aeb1ce71.zip
add test to moa-sig module that facilities decoding of PDF embeded CAdES signatures
Diffstat (limited to 'eaaf_modules/eaaf_module_moa-sig/src/test/java/console/PdfSigDecoder.java')
-rw-r--r--eaaf_modules/eaaf_module_moa-sig/src/test/java/console/PdfSigDecoder.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/eaaf_modules/eaaf_module_moa-sig/src/test/java/console/PdfSigDecoder.java b/eaaf_modules/eaaf_module_moa-sig/src/test/java/console/PdfSigDecoder.java
new file mode 100644
index 00000000..28338746
--- /dev/null
+++ b/eaaf_modules/eaaf_module_moa-sig/src/test/java/console/PdfSigDecoder.java
@@ -0,0 +1,40 @@
+package console;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.springframework.util.Base64Utils;
+import org.springframework.util.StreamUtils;
+
+import iaik.asn1.ASN1;
+import iaik.asn1.CodingException;
+
+public class PdfSigDecoder {
+
+ /**
+ * Decode a CAdES signature that is located in a PDF document.
+ *
+ * @param args not supported yes
+ * @throws CodingException In case of an ASN.1 decoding error
+ * @throws IOException In case of a general error
+ * @throws UnsupportedEncodingException In case of a general error
+ */
+ public static void main(String[] args) throws CodingException, UnsupportedEncodingException, IOException {
+ InputStream is = PdfSigDecoder.class.getResourceAsStream("/pdf_cades_3.hex");
+ String test = new String(StreamUtils.copyToByteArray(is), "UTF-8");
+ test = test.replaceAll("\\n", "");
+ final byte[] bytes = new byte[test.length() / 2];
+ for (int i = 0; i < test.length() / 2; i++) {
+ bytes[i] = (byte) Integer.parseInt(test.substring(i * 2, i * 2 + 2), 16);
+ }
+ Base64Utils.encodeToString(bytes);
+
+ final ASN1 asn1 = new ASN1(bytes);
+
+ System.out.println(asn1.toString());
+ System.out.println(Base64Utils.encodeToString(bytes));
+
+ }
+
+}