最近在做3DES加密,在本地window下面运行ok的程序,放到linux环境上竟然报错:
java.security.NoSuchAlgorithmException: Cannot find any provider supporting DESede/CBC/PKCS5Padding
at javax.crypto.Cipher.getInstance(Cipher.java:524)
at com.haha.encrypt.ThreeDES.encryptMode(ThreeDES.java:30)
at com.haha.encrypt.ThreeDES.encryptString(ThreeDES.java:101)
at com.haha.mina.MinaServerHandler.sessionIdle(MinaServerHandler.java:91)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.sessionIdle(DefaultIoFilterChain.java:665)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionIdle(DefaultIoFilterChain.java:398)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1000(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionIdle(DefaultIoFilterChain.java:755)
at org.apache.mina.core.filterchain.IoFilterAdapter.sessionIdle(IoFilterAdapter.java:95)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionIdle(DefaultIoFilterChain.java:398)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1000(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionIdle(DefaultIoFilterChain.java:755)
at org.apache.mina.core.filterchain.IoFilterAdapter.sessionIdle(IoFilterAdapter.java:95)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionIdle(DefaultIoFilterChain.java:398)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireSessionIdle(DefaultIoFilterChain.java:391)
at org.apache.mina.core.session.AbstractIoSession.notifyIdleSession0(AbstractIoSession.java:1303)
at org.apache.mina.core.session.AbstractIoSession.notifyIdleSession(AbstractIoSession.java:1289)
at org.apache.mina.core.session.AbstractIoSession.notifyIdleness(AbstractIoSession.java:1274)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.notifyIdleSessions(AbstractPollingIoProcessor.java:760)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$900(AbstractPollingIoProcessor.java:67)
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1135)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
对比了下Security.getProviders()
window下:
INFO 2014-04-30 10:32:12 ServerStarter:67 - 0[SUN]
INFO 2014-04-30 10:32:12 ServerStarter:67 - 1[SunRsaSign]
INFO 2014-04-30 10:32:12 ServerStarter:67 - 2[SunEC]
INFO 2014-04-30 10:32:12 ServerStarter:67 - 3[SunJSSE]
INFO 2014-04-30 10:32:12 ServerStarter:67 - 4[SunJCE]
INFO 2014-04-30 10:32:12 ServerStarter:67 - 5[SunJGSS]
INFO 2014-04-30 10:32:12 ServerStarter:67 - 6[SunSASL]
INFO 2014-04-30 10:32:12 ServerStarter:67 - 7[XMLDSig]
INFO 2014-04-30 10:32:12 ServerStarter:67 - 8[SunPCSC]
INFO 2014-04-30 10:32:12 ServerStarter:67 - 9[SunMSCAPI]
linux下:
INFO 2014-04-30 10:33:55 ServerStarter:66 - 0[SUN]
INFO 2014-04-30 10:33:55 ServerStarter:66 - 1[SunRsaSign]
INFO 2014-04-30 10:33:55 ServerStarter:66 - 2[SunJSSE]
INFO 2014-04-30 10:33:55 ServerStarter:66 - 3[SunJGSS]
INFO 2014-04-30 10:33:55 ServerStarter:66 - 4[SunSASL]
INFO 2014-04-30 10:33:55 ServerStarter:66 - 5[XMLDSig]
INFO 2014-04-30 10:33:56 ServerStarter:66 - 6[SunPCSC]
怀疑是缺少SunJCE造成的,但是在linux的JAVA_HOME/jre/lib/ext目录下,有sunjce_provider.jar包,所以很奇怪。
百思不得其姐,最后在一篇文章里,找到一句话,“找到一个 sunjce_provider.jar 的文件扔到你类路径里”,结果,ok了。。。。
java.security.NoSuchAlgorithmException: Cannot find any provider supporting DESede/CBC/PKCS5Padding
原文地址:http://blog.csdn.net/linyu19872008/article/details/24773457