java ecdh算法,JSch算法协商失败

我尝试通过Java连接SFTP服务器。

我有一个错误。

com.jcraft.jsch.JSchException:算法协商失败

这是POM:

com.jcraft

jsch

0.1.53

这是日志:

INFO: Connecting to **"FTP ADRESS"** port 22

INFO: Connection established

INFO: Remote version string: SSH-2.0-Maverick_SSHD

INFO: Local version string: SSH-2.0-JSCH-0.1.53

INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256

INFO: aes256-ctr is not available.

INFO: aes192-ctr is not available.

INFO: aes256-cbc is not available.

INFO: aes192-cbc is not available.

INFO: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521

INFO: diffie-hellman-group14-sha1 is not available.

INFO: ecdh-sha2-nistp256 is not available.

INFO: ecdh-sha2-nistp384 is not available.

INFO: ecdh-sha2-nistp521 is not available.

INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521

INFO: ecdsa-sha2-nistp256 is not available.

INFO: ecdsa-sha2-nistp384 is not available.

INFO: ecdsa-sha2-nistp521 is not available.

INFO: SSH_MSG_KEXINIT sent

INFO: SSH_MSG_KEXINIT received

INFO: kex: server: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1

INFO: kex: server: ssh-rsa

INFO: kex: server: aes256-cbc,aes192-cbc

INFO: kex: server: aes256-cbc,aes192-cbc

INFO: kex: server: hmac-sha1,hmac-sha1-96

INFO: kex: server: hmac-sha1,hmac-sha1-96

INFO: kex: server: none

INFO: kex: server: none

INFO: kex: server:

INFO: kex: server:

INFO: kex: client: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1

INFO: kex: client: ssh-rsa,ssh-dss

INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc

INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc

我收到此错误,尝试解决。我无法访问SFTP服务器来下载或更新任何文件等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是 Java 实现 ECDH 算法的示例代码: ```java import java.security.*; import java.security.spec.*; import javax.crypto.*; import javax.crypto.spec.*; public class ECDHDemo { public static void main(String[] args) throws Exception { // 创建椭圆曲线密钥对生成器 KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC"); // 使用 secp256r1 椭圆曲线 kpg.initialize(new ECGenParameterSpec("secp256r1")); // 生成密钥对 KeyPair kp1 = kpg.generateKeyPair(); KeyPair kp2 = kpg.generateKeyPair(); // 获取公钥和私钥 PublicKey pubKey1 = kp1.getPublic(); PrivateKey priKey1 = kp1.getPrivate(); PublicKey pubKey2 = kp2.getPublic(); PrivateKey priKey2 = kp2.getPrivate(); // ECDH 密钥协商 KeyAgreement ka1 = KeyAgreement.getInstance("ECDH"); ka1.init(priKey1); ka1.doPhase(pubKey2, true); byte[] secret1 = ka1.generateSecret(); KeyAgreement ka2 = KeyAgreement.getInstance("ECDH"); ka2.init(priKey2); ka2.doPhase(pubKey1, true); byte[] secret2 = ka2.generateSecret(); // 验证协商的密钥是否相同 if (MessageDigest.isEqual(secret1, secret2)) { System.out.println("ECDH 密钥协商成功!"); } else { System.out.println("ECDH 密钥协商失败!"); } } } ``` 在上面的示例代码中,我们使用 `secp256r1` 椭圆曲线生成密钥对,并使用 ECDH 算法进行密钥协商。具体步骤如下: 1. 通过 `KeyPairGenerator` 生成密钥对。 2. 获取公钥和私钥。 3. 创建 `KeyAgreement` 实例,初始化为自己的私钥。 4. 使用 `doPhase` 方法将对方的公钥作为输入,并执行密钥协商。 5. 使用 `generateSecret` 方法生成协商的密钥。 6. 验证双方协商的密钥是否相同,如果相同则密钥协商成功。 值得注意的是,ECDH 密钥协商只能协商出一个共享密钥,而且这个共享密钥不是公钥或私钥,它只能用于对称加密。因此,在实际应用中,我们通常需要使用协商出的共享密钥来加密通信内容。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值