开发者

file upload using https error?

My code is,

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

  try {
  // Open a secure connection.开发者_如何学JAVA
  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();

Here it shows an error as,

java.io.IOException: DerInputStream.getLength(): lengthTag=109, too big. at sun.security.util.DerInputStream.getLength(Unknown Source) at sun.security.util.DerValue.init(Unknown Source) at sun.security.util.DerValue.(Unknown Source) at 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)

Can any one help me what is the problem and to resolve it?


The keystore you're trying to load probably isn't an instance of a Sun PKCS12 keystore. Issue the following command to find out the type of the keystore...

keytool -list -keystore <keystore_location>

You'll find output that looks like...

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 76 entries

...

In this case the Keystore is a JKS keystore (which I'm guessing yours is too) and you'll want to do

KeyStore.getInstance("JKS");

Instead of what you have.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜