Purpose of pubkey parameter of JSch.addIdentity

痞子三分冷 提交于 2021-02-08 06:33:15

问题


I'm referring to

public void addIdentity(String name,
                        byte[] prvkey,
                        byte[] pubkey,
                        byte[] passphrase)
                 throws JSchException

I tried using it and no matter what input I give as pubkey (doesn't matter the length or the characters), as long as the prvkey matches, the connection will be established.

Is this the normal behavior? Why is the pubkey even requested then?

After a bit more research, it seems like the pubkey is not ignored on purpose, but it has to respect certain rules to be taken into consideration, otherwise it still seems to consider only the prvkey.


回答1:


Having unencrypted public key is particularly useful, when you have multiple passphrase-encrypted key-pairs loaded into the JSch (or any SSH library/client).

Having the unencrypted public key, the client (JSch) can use the public key to ask the server, whether it recognizes the key. If it does, only then the JSch will ask for the passphrase to decrypt the private key.

If you have only one key or if all your keys are unencrypted, you do not need to specify the pubkey (use null).



来源:https://stackoverflow.com/questions/59661442/purpose-of-pubkey-parameter-of-jsch-addidentity

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