summaryrefslogtreecommitdiff
path: root/eaaf_modules/eaaf_module_moa-sig/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_modules/eaaf_module_moa-sig/src/test/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));
+
+ }
+
+}