https://bz.apache.org/bugzilla/show_bug.cgi?id=64772
Bug ID: 64772
Summary: docx file signing failed
Product: POI
Version: 4.1.2-FINAL
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: POIFS
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
I downloaded poi-src-4.1.2-20200217 and signed the docx file. The signature
failed. (Note: the xlsx file is signed successfully.) My test program is as
follows:
KeyPair keyPair;
char password[] = "123456".toCharArray();
File file = new File("D:\\1\\data\\付筠1.pfx");
KeyStore keystore =
KeyStore.getInstance("PKCS12");//KeyStoreException
FileInputStream fis = new
FileInputStream(file);//FileNotFoundException
keystore.load(fis,
password);//CertificateException,NoSuchAlgorithmException
fis.close();// IOException
// extracting private key and certificate
String alias =
"5a90de991425c0f3b8a1215eb0587726_183c7506-734c-4aeb-b291-ebeed563f78d"; //
alias of the keystore entry
Key key = keystore.getKey(alias,
password);//UnrecoverableKeyException, NoSuchAlgorithmException
X509Certificate x509 =
(X509Certificate)keystore.getCertificate(alias);//KeyStoreException
keyPair = new KeyPair(x509.getPublicKey(),
(PrivateKey)key);
// filling the SignatureConfig entries (minimum fields,
more options are available ...)
SignatureConfig signatureConfig = new
SignatureConfig();
signatureConfig.setKey(keyPair.getPrivate());
signatureConfig.setSigningCertificateChain(Collections.singletonList(x509));
// adding the signature document to the package
SignatureInfo si = new SignatureInfo();
OPCPackage pkg = OPCPackage.open(new
File("D:\\1\\data\\e2.xlsx"),
PackageAccess.READ_WRITE);//InvalidFormatException
signatureConfig.setOpcPackage(pkg);
si.setSignatureConfig(signatureConfig);
si.confirmSignature();//
MarshalException,XMLSignatureException
boolean b = si.verifySignature();
//assert (b);
System.out.println(b);
// write the changes back to disc
pkg.close();
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]