如何在java项目中将新的pfx cert文件更改为旧的jks文件

时间:2016-06-08 06:44:49

标签: java keystore pfx jarsigner jks

有一个java项目,并且有一个jks认证文件。但它已经过时了(过期了)。现在我必须将其更改为新的pfx认证文件。但我不知道我是怎么做的。

这是关于当前项目的一些信息;

这是带有旧jks文件配置的pom.xml

<profile>
            <id>sign-base</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jarsigner-plugin</artifactId>
                        <version>1.2</version>
                        <executions>
                            <execution>
                                <id>sign</id>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>verify</id>
                                <goals>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <verbose>true</verbose>
                            <storepass>OldJKSKeystorePass</storepass>
                            <keypass>OldJKSKeyPass</keypass>
                            <arguments>
                                <argument>-tsa</argument>
                                <argument>http://timestamp.globalsign.com/scripts/timestamp.dll</argument>
                            </arguments>
                            <keystore>${pom.parent.basedir}${file.separator}OldJKSFile.jks</keystore>
                            <alias>1</alias>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

这里有一个名为“SpecialHttpsClient”的java类扩展默认的httpsClient,它有一个类似的方法。 mykeystore文件在资源包下,我不知道。

private SSLSocketFactory newSslSocketFactory() {
        InputStream in =null;

        try {
            KeyStore trusted = KeyStore.getInstance("JKS");
            in = this.getClass().getResourceAsStream("/mykeystore");
            trusted.load(in, "mykeystorepass".toCharArray());

            SSLSocketFactory sf = new SSLSocketFactory(trusted);
            sf.setHostnameVerifier(sslSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

            return sf;
        } catch (Exception e) {
            logger.error("An error was occurred while creating SSLSocketFactory!***************", e);
            return null;
        } finally {
            if(in!=null )
                try {
                    in.close();
                } catch (IOException e) {
                    logger.error("An error was occurred while creating SSLSocketFactory!***************", e);
                }
        }
    }

这是另一个名为SpecialHttpsConnection的类,并且有一个类似的方法。我对文档文件一无所知。

private static TrustManagerFactory getTrustManagerFactory() throws Exception {

        if(trustManagerFactory==null) {
            try {
                KeyStore trusted =null;
                trusted = KeyStore.getInstance("JKS");
                InputStream in = SpecialHttpsConnection.class.getResourceAsStream("/document");
                try {
                    trusted.load(in, "T1@ePudf27?wE".toCharArray());
                } finally {
                    in.close();
                }

                trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                trustManagerFactory.init(trusted);

            } catch(Exception e)  {
                logger.error("An error was occurred while creating TrustManagerFactory!***************",e);
                throw e;
            }

        }

        return trustManagerFactory;
    }

我的问题是;我怎么能用旧的改变“mynewcert.pfx”文件?

1 个答案:

答案 0 :(得分:0)

以下是jarsigner的解决方案,可能对某人有用

打开cmd并输入 cd转至/ your / jre / bin / directory /

输入

keytool -importkeystore -srckeystore“c:\ mypfxfolderdirectory \ mypfxfile.pfx”-srcstoretype PKCS12 -destkeystore“c:\ mypfxfolderdirectory \ myjksfile.jks”-deststoretype JKS -srcstorepass pfxFilePass -deststorepass jksFileStorePass -ssccalias 1 -destalias 1 -destkeypass jksFileKeyPass -noprompt

之后你的jks文件将使用两个密码创建:store pass,key pass。