Java 1.7 + JSCH: java.security.InvalidKeyException: Key is too long for this algorithm

雨燕双飞 提交于 2019-12-05 02:03:25

We ended up swapping JSCH out for SSHJ. It depends on the BouncyCastle crypto libraries rather than on Java's built-in crypto packages, and is capable of connecting to our server with no problems.

Preben Valeur

You can force JSCH to use SHA256 instead of SHA1 with keysize > 1024 (which JSSE doesn't allow anymore) like this:

java.util.Properties configuration = new java.util.Properties();
configuration.put("kex", "diffie-hellman-group-exchange-sha256");           
configuration.put("StrictHostKeyChecking", "no");
session.setConfig(configuration);

Actually, the bug for this behaviour that was filed against the JDK was not closed - the decision to close it was reverted and it has been fixed a few days later. It has later been backported, so upgrading to Java SE 8u45 (or higher) solves the issue as well.

Install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files click here to download

Replace local_policy.jar and US_export_policy.jar with unrestricted policy files at following location : Java\jre7\lib\security\

I had similar problem while encryption of data with ibm jre version 1.5 and tomcat.

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