JSch: check passphrase with secret key before trying to connect

For a fairly simple application, which mainly depends on ssh connections created through JSch, I wanted to ask for a passphrase on the login screen, try to decrypt the private key, and if not, return to the login window.

I could not find a way to find out if the call

jsch.addIdentity(keyfile, prvkey, pubkey, passphrase); 

ended correctly, even if I see in the code that the decryption has already been verified, and I believe that he already knows that the code phrase is incorrect.

Is there any way to define a passphrase before trying to establish a session?

Thanks.

+4
source share
1 answer

You can use the KeyPair class for your requirements as follows:

 KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey); System.out.println(kpair.decrypt(passphrase)); 
+4
source

Source: https://habr.com/ru/post/1486189/


All Articles