From 68e96ea339f58efb772b4ad77f617347aeb1ce71 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 6 Apr 2020 09:54:23 +0200 Subject: add test to moa-sig module that facilities decoding of PDF embeded CAdES signatures --- .../src/test/java/console/PdfSigDecoder.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 eaaf_modules/eaaf_module_moa-sig/src/test/java/console/PdfSigDecoder.java (limited to 'eaaf_modules/eaaf_module_moa-sig/src/test/java') 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)); + + } + +} -- cgit v1.2.3