问题
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