Search in sources :

Example 1 with IdentityRepository

use of com.jcraft.jsch.IdentityRepository in project dbeaver by serge-rider.

the class SSHUtils method isKeyEncrypted.

public static boolean isKeyEncrypted(String privKeyPath) {
    // Check whether this key is encrypted
    if (privKeyPath != null) {
        // Determine whether public key is encrypted
        try {
            JSch testSch = new JSch();
            testSch.addIdentity(privKeyPath);
            IdentityRepository ir = testSch.getIdentityRepository();
            List<Identity> identities = ir.getIdentities();
            for (Identity identity : identities) {
                if (identity.isEncrypted()) {
                    return true;
                }
            }
        } catch (JSchException e) {
            // Something went wrong
            log.debug("Can't check private key encryption: " + e.getMessage());
        }
    }
    return false;
}
Also used : JSchException(com.jcraft.jsch.JSchException) JSch(com.jcraft.jsch.JSch) Identity(com.jcraft.jsch.Identity) IdentityRepository(com.jcraft.jsch.IdentityRepository)

Example 2 with IdentityRepository

use of com.jcraft.jsch.IdentityRepository in project dbeaver by dbeaver.

the class SSHUtils method isKeyEncrypted.

public static boolean isKeyEncrypted(String privKeyPath) {
    // Check whether this key is encrypted
    if (privKeyPath != null) {
        // Determine whether public key is encrypted
        try {
            JSch testSch = new JSch();
            testSch.addIdentity(privKeyPath);
            IdentityRepository ir = testSch.getIdentityRepository();
            List<Identity> identities = ir.getIdentities();
            for (Identity identity : identities) {
                if (identity.isEncrypted()) {
                    return true;
                }
            }
        } catch (JSchException e) {
            // Something went wrong
            log.debug("Can't check private key encryption: " + e.getMessage());
        }
    }
    return false;
}
Also used : JSchException(com.jcraft.jsch.JSchException) JSch(com.jcraft.jsch.JSch) Identity(com.jcraft.jsch.Identity) IdentityRepository(com.jcraft.jsch.IdentityRepository)

Aggregations

Identity (com.jcraft.jsch.Identity)2 IdentityRepository (com.jcraft.jsch.IdentityRepository)2 JSch (com.jcraft.jsch.JSch)2 JSchException (com.jcraft.jsch.JSchException)2