Search in sources :

Example 1 with Identity

use of com.jcraft.jsch.Identity 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 Identity

use of com.jcraft.jsch.Identity in project artisynth_core by artisynth.

the class SimpleIdentityRepository method remove.

public synchronized boolean remove(Identity id) {
    if (id == null)
        return false;
    for (Identity identity : identities) {
        if (id.equals(identity)) {
            identities.removeElement(id);
            // erase private key
            id.clear();
            return true;
        }
    }
    return false;
}
Also used : Identity(com.jcraft.jsch.Identity)

Example 3 with Identity

use of com.jcraft.jsch.Identity 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)3 IdentityRepository (com.jcraft.jsch.IdentityRepository)2 JSch (com.jcraft.jsch.JSch)2 JSchException (com.jcraft.jsch.JSchException)2