I have a word/docx file which has been digitally signed.
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)
How can I do this from Java?
The following link didn't help me as I already have a signed document.
I tried with apache poi, but unsuccess, return only nulls
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<SignaturePart> iter = si.getSignatureParts().iterator();
while (iter.hasNext()) {
SignaturePart element = iter.next();
System.out.println("getSigner " + element.getSigner());
List<X509Certificate> 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());
}
}
but checking isValid, returned true..