1

我的代码是,

 Properties systemProps = System.getProperties();
    systemProps.put( "javax.net.ssl.trustStore",    
   System.getProperty("catalina.home")+fs+".keystore");
    System.setProperties(systemProps);

  try {
  // Open a secure connection.
  URL url = new URL( "https://192.168.6.45:8181/erp_adapter/UploadFile" );
  String requestParams = "uid=sdfn&password=rsdftesan&active=y&type=F";
  HttpsURLConnection con = (HttpsURLConnection) url.openConnection();

  // Set up the connection properties
  con.setRequestProperty( "Connection", "close" );
  con.setDoInput(true);
  con.setDoOutput(true);
  con.setUseCaches(false);
  con.setConnectTimeout( 30000 );
  con.setReadTimeout( 30000 );
  con.setRequestMethod( "POST" );
  con.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );
  con.setRequestProperty( "Content-Length", Integer.toString(requestParams.length()) );

  // Set up the user authentication portion of the handshake with the private
  // key provided by NAIMES Tech Support.
  //   Based on an example posted by Torsten Curdt on his blog:
  //     http://vafer.org/blog/20061010073725 (as of Nov, 2009)
  File pKeyFile = new File(System.getProperty("catalina.home")+fs+".keystore");
  String pKeyPassword = "UB#20abba";
  KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
  KeyStore keyStore = KeyStore.getInstance("PKCS12");
  InputStream keyInput = new FileInputStream(pKeyFile);
  //byte[] Password=pKeyPassword.getBytes();
  keyStore.load(keyInput, pKeyPassword.toCharArray());
  keyInput.close();

在这里它显示一个错误,

java.io.IOException: DerInputStream.getLength(): lengthTag=109,太大了。在 sun.security.util.DerInputStream.getLength(Unknown Source) 在 sun.security.util.DerValue.init(Unknown Source) 在 sun.security.util.DerValue.(Unknown Source) 在 com.sun.net.ssl。 internal.pkcs12.PKCS12KeyStore.engineLoad(Unknown Source) at java.security.KeyStore.load(Unknown Source) at com.gofrugal.raymedi.erp.util.AidapClient.main(AidapClient.java:58)

任何人都可以帮助我解决问题并解决它吗?

4

1 回答 1

4

您尝试加载的密钥库可能不是 Sun PKCS12 密钥库的实例。发出以下命令以找出密钥库的类型...

keytool -list -keystore <keystore_location>

你会发现输出看起来像......

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 76 entries

...

在这种情况下,密钥库是一个 JKS 密钥库(我猜你的也是),你会想要这样做

KeyStore.getInstance("JKS");

而不是你所拥有的。

于 2011-01-29T13:11:10.797 回答