当前位置: 代码迷 >> Eclipse >> java.security.NoSuchAlgorithmException: Cannot find any provider
  详细解决方案

java.security.NoSuchAlgorithmException: Cannot find any provider

热度:430   发布时间:2016-04-23 18:58:12.0
求解一加密解密的怪问题,哪位专家知道麻烦解答一下!谢谢!!!!
问题是:在Eclipse中启动tomcat,然后在登陆页面输入密码登陆时就报以下错误,而单独启动tomcat,不在Eclipse中启动tomcat,登陆页面输入密码却能正常登陆!

(1)异常日志
2009-01-06 09:16:03 [com.opensymphony.xwork2.validator.ActionValidatorManagerFactory]-[INFO] Detected AnnotationActionValidatorManager, initializing it...
java.security.NoSuchAlgorithmException: Cannot find any provider supporting DESede
at javax.crypto.Cipher.getInstance(DashoA13*..)

(2) 报异常代码行:(Cipher c1 = Cipher.getInstance(Algorithm))

/**
* 解密操作
*/ 
public static String decryptMode(String str)
{
try
{
// 将string转换回来成为byte数组:
BASE64Decoder dec = new BASE64Decoder();
byte[] src = dec.decodeBuffer(str);

// 生成密钥
SecretKey deskey = new SecretKeySpec(keyBytes, Algorithm);

// 解密
Cipher c1 = Cipher.getInstance(Algorithm);[color=#FF0000][/color]
c1.init(Cipher.DECRYPT_MODE, deskey);
byte[] deSrc = c1.doFinal(src);

return new String(deSrc);
}
catch (java.security.NoSuchAlgorithmException e1)
{
e1.printStackTrace();
}
catch (javax.crypto.NoSuchPaddingException e2)
{
e2.printStackTrace();
}
catch (java.lang.Exception e3)
{
e3.printStackTrace();
}
return null;
}

(3)运行环境配置:
apache-tomcat-5.5.27
jdk1.6.0_06
Eclipse Platform Version: 3.3.1.1

(4)我怀疑是Eclipse环境配置或包引用有问题,要不怎么单独在外启动tomcat就能正常,不会报以上错误;

------解决方案--------------------
确实有所不同,遇到过类似问题,冒解决,呵呵
1.Cipher c1 = Cipher.getInstance(Algorithm); 
直接把Algorithm换成"DESede"试试
2.换个JDK,比如换个1.5的试试看

------解决方案--------------------
出现此错误是因为Eclipse和默认启动Tomcat所查找的jar包不同所造成的。
解决方法就是把tomcat参照的加密处理的jar拷贝到WEB-INF/lib下面。
  相关解决方案