https://bz.apache.org/bugzilla/show_bug.cgi?id=64772

--- Comment #2 from lavender <[email protected]> ---
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\\a1.docx"),
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]

Reply via email to