2016-06-08 28 views
0

Es gibt ein Java-Projekt und hat eine JKS-Zertifizierungsdatei. Aber es ist alt (abgelaufen). Jetzt muss ich eine neue pfx-Zertifizierungsdatei ändern. Aber ich weiß nicht, wie ich es mache.Wie man neue pfx cert-Datei in alte jks-Datei in Java-Projekt ändern

hier sind einige Informationen über das aktuelle Projekt;

das ist pom.xml mit alten JKS-Datei Konfiguration

<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> 

Hier gibt es eine Java-Klasse, die Namen „SpecialHttpsClient“ erweitern Standard httpsClient ist, und es hat ein Verfahren ähnlich. Die Datei mykeystore befindet sich im Ressourcenpaket und ich weiß nichts darüber.

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); 
       } 
     } 
    } 

ist hier eine andere Klasse, die Namen SpecialHttpsConnection ist und ein Verfahren wie das hat. Ich weiß nichts über die Dokumentdatei.

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, "[email protected]?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; 
    } 

Mein Problem ist das; Wie kann ich "mynewcert.pfx" Datei mit alten ändern?

+0

Wenn Sie Ihren Code nicht ändern möchten, müssen Sie Ihre JKS-Datei mit 'keytool' manuell in die PKCS12-Datei konvertieren. –

Antwort

0

Hier ist die Lösung für jarsigner,

offen cmd

für jemanden nützlich sein kann und cd/Ihr/jre/bin/Verzeichnis/

Typ

keytool gehen geben - importkeystore -srckeystore "c: \ mpfxfolderdirectory \ mpfxfile.pfx" -srcstoretyp PKCS12 -destkeystore "c: \ mpfxfolderdirectory \ myjksfile.jks" -deststoretyp JKS -srcstorepass pfxFilePass -deststorepass jksFileStorePass -srcalisas 1 -deleases 1 -destkeypass jksFileKeyPass -noprompt

Danach wird Ihre JKS-Datei mit zwei Passwörtern erstellt: Store Pass, Key Pass.