How do I get javax.crypto classes such as javax.crypto.Cipher to work on a servlet with jboss?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 18:35:27

问题


My application validates a license file in order for it to work. It does this by calling javax.crypto.Cipher.getInstance("DES","SunJCE") inorder to decipher the license key file.

When I run my application locally everything works fine but when I deploy my application with jboss and get to the point where I want to validate the license file on the servlet, I get the following error:

java.lang.SecurityException: JCE cannot authenticate the provider SunJCE
  at javax.crypto.Cipher.getInstance(DashoA13*..)
  at javax.crypto.Cipher.getInstance(DashoA13*..)

Like I said, it works fine from command prompt and eclipse, but not as a servlet on jboss. Does anybody have any idea what I need to do? I am using jdk 1.6 and jboss as 7.

Thanks


回答1:


There are a couple of possible issues that come in mind, it seems to be a problem with classpath when sun/oracle jvm try to authenticate provider jars

  • check that all security jars are under the <jdk_home>/jre/lib/ext of the jvm that runs jboss (ie US_export_policy.jar, sunjce_provider.jar, local_policy.jar....)

  • about US_export_policy.jar and local_policy.jar be sure to have downloaded the unrestricted version

  • java.security file in <jdk_home>/jre/lib/security: be sure to have a line similar to security.provider.X=com.sun.crypto.provider.SunJCE where X is a number

  • be sure that sunJCE provider jar is not in you WEB-INF/lib




回答2:


I figured out what was wrong with my code. Earlier in the code for some reason someone did the following:

if (SunJCEinProviders) 
{
Security.removeProvider("SunJCE");
}   

int i = Security.insertProviderAt(new  com.sun.crypto.provider.SunJCE(),1);

So for some reason we were removing javas initial SunJCE provider then adding a new one and this new one was failing to be authenticated.



来源:https://stackoverflow.com/questions/6932681/how-do-i-get-javax-crypto-classes-such-as-javax-crypto-cipher-to-work-on-a-servl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!