使用JSCH创建SFTP时出现此错误。 我试图通过sftp连接到远程服务器来传输文件,但是在调用connect方法时发生错误。
java.lang.ExceptionInInitializerError
at javax.crypto.Cipher.getInstance(DashoA13*..)
at com.jcraft.jsch.jce.AES256CTR.init(AES256CTR.java:56)
at com.jcraft.jsch.Session.checkCipher(Session.java:2072)
at com.jcraft.jsch.Session.checkCiphers(Session.java:2049)
at com.jcraft.jsch.Session.send_kexinit(Session.java:592)
at com.jcraft.jsch.Session.connect(Session.java:286)
at com.jcraft.jsch.Session.connect(Session.java:162)
at scb.frame.runner.ServerSetup.contactServer(ServerSetup.java:56)
Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs
at javax.crypto.SunJCE_b.<clinit>(DashoA13*..)
... 34 more
Caused by: java.lang.SecurityException: Cannot locate policy or framework files!
at javax.crypto.SunJCE_b.i(DashoA13*..)
at javax.crypto.SunJCE_b.g(DashoA13*..)
at javax.crypto.SunJCE_b$1.run(DashoA13*..)
at java.security.AccessController.doPrivileged(Native Method)
... 35 more
我的连接代码:
String host = serverProperties.getProperty("Host");
String username = serverProperties.getProperty("Username");
String password = serverProperties.getProperty("Password");
JSch jsch = new JSch();
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Session session;
try {
session = jsch.getSession(username, host, 22);
session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
sftpChannel.get(sourceFile,destFile);
Same Program的命令行版本我可以毫无例外地运行! 此外,来自Jcraft [link] http://www.jcraft.com/jsch/examples/Sftp.java.html网站的SFTP示例运行良好。
答案 0 :(得分:1)
它与Java的安全限制有关。默认情况下,密钥大小限制为128位。从您的堆栈跟踪中,我发现您正在尝试使用AES 256位加密。
要解决您的问题,请访问Java的网站并下载Java Cryptography Extension(JCE)Unlimited Strength Jurisdiction Policy Files:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
(在底部找到)
将它们安装在你的JRE中你很高兴:)感谢美国政府......