Question

I want to access ssl webservice.

  1. I have generated the client bindings in Netbeans
  2. Generated JKS and imported client pfx file to the client.jks with ckeystorepwd and calias
  3. Webservice Producer has shared server.jks with srvalias and srvkeystorepwd
  4. I have configured the Keystore and TrustStore in NetBeans IDE and I am running Main.java and

I am able to consume the webservice. I want to consume the webservice without NetBeansIDE. I need to configure the Keystroe and Truststore (client.jks,server.jks) to the environment pragmatically.

I have included the below code in my Main.java but it is giving below error , Please guide me how can I configure the keystroe ,truststore.

Main.java Code

System.setProperty("-Djavax.net.ssl.keyStore",JKSFILE);
System.setProperty("-Djavax.net.ssl.keyStorePassword",JKSPWD);
System.setProperty("javax.net.ssl.keyStoreType", "JKS");

System.setProperty("-Djavax.net.ssl.trustStore",JKSFILET);
System.setProperty("-Djavax.net.ssl.trustStorePassword",JKSPWDT);
System.setProperty("javax.net.ssl.requireClientAuth", "true");  
System.setProperty("com.sun.xml.ws.transport.http.client.
    HttpTransportPipe.dump","true");

URL u;  
u = new URL(MAIN_URL);  
IWebService service = new 
WebService(u).getWS2007HttpBindingIWebService();

Error

SEVERE: WSS1906: Invalid key provided for encryption/decryption.
java.security.InvalidKeyException: Illegal key size or default parameters
    at javax.crypto.Cipher.a(DashoA13*..)
    at javax.crypto.Cipher.a(DashoA13*..)
    at javax.crypto.Cipher.a(DashoA13*..)
    at javax.crypto.Cipher.init(DashoA13*..)
    at javax.crypto.Cipher.init(DashoA13*..)
    at com.sun.xml.ws.security.opt.impl.enc.CryptoProcessor.initCipher(CryptoProcessor.java:125)
    at com.sun.xml.ws.security.opt.impl.enc.CryptoProcessor.encryptData(CryptoProcessor.java:269)
    at com.sun.xml.ws.security.opt.impl.enc.CryptoProcessor.encrypt(CryptoProcessor.java:153)
    at com.sun.xml.ws.security.opt.impl.util.CVDataHandler.writeTo(CVDataHandler.java:69)
    at javax.activation.ObjectDataContentHandler.writeTo(Unknown Source)
    at javax.activation.DataHandler$1.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Exception in thread "DataHandler.getInputStream" com.sun.xml.wss.impl.XWSSecurityRuntimeException: Unable to calculate cipher value as invalid key was provided
Was it helpful?

Solution

Resolved the issue,

I was not using the same JVM where I have copied the policy jar as part of JCE-6 configuration in Eclipse environment.

Now I have changed the JRE for the project and able to run the program without any issue.

C:\Program Files (x86)\Java\jdk1.6.0_33\bin\java -jar "WSClient.jar"

OTHER TIPS

You may have to install the unlimited strength encryption policy files: http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html

Java doesn't ship with strong encryption due to US export laws against encryption, but you can enable it separately by replacing the local_policy.jar and US_export_policy.jar from the download above in $JAVA_HOME/lib/security.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top