title: How do I retrieve the digital signature data from a Word file using Java?
body: <p>I have a word/docx file which has been digitally signed.</p>
  
  <p>I need to open the file and read the signature subject, valid from, valid to and the rest of the details (including the RSA public key)</p>
  
  <p>How can I do this from Java?</p>
  
  <p>The following link didn't help me as I already have a signed document.</p>
  
  <p><a href="https://stackoverflow.com/questions/11410770/java-load-rsa-public-key-from-file">Load RSA public key from file</a></p>
  
  <p>I tried with apache poi, but unsuccess, return only nulls</p>
  
  <pre><code>public static void main(String[] args) throws IOException, XmlException {
          String fileName = "test.docx";
          OPCPackage pkg = null;
          try {
              pkg = OPCPackage.open(fileName, PackageAccess.READ_WRITE);
          } catch (InvalidFormatException ex) {
              ex.printStackTrace();
          }
          SignatureConfig sic = new SignatureConfig();
          sic.getProxyUrl();
          sic.setOpcPackage(pkg);
          SignatureInfo si = new SignatureInfo();
          si.setSignatureConfig(sic);
          boolean isValid = si.verifySignature();
  
          System.out.println("isValid " + isValid);
  
  
          Iterator&lt;SignaturePart&gt; iter = si.getSignatureParts().iterator();
          while (iter.hasNext()) {
              SignaturePart element = iter.next();
  
              System.out.println("getSigner " + element.getSigner());
  
              List&lt;X509Certificate&gt; list = element.getCertChain();
              for (X509Certificate cc : list) {
                  System.out.println("getSigAlgName " + cc.getSigAlgName());
                  System.out.println("getSigAlgOID " + cc.getSigAlgOID());
                  System.out.println("getNotAfter " + cc.getNotAfter());
                  System.out.println("getNotBefore " + cc.getNotBefore());
              }
  
  
          }
  </code></pre>
  
  <p>but checking isValid, returned true..</p>