public static void setIdentity(JSch jsch, IdentityKey identityKey) throws SSHException { byte[] passPhrase = identityKey.getPassPhrase(); if (identityKey instanceof KeyFile) { try { jsch.addIdentity(((KeyFile) identityKey).getKeyFilePath(), passPhrase); } catch (JSchException e) { throw new SSHException("The keyFilePath is invalid.", e); } } else { try { jsch.addIdentity(((KeyData) identityKey).getKeyName(), ((KeyData) identityKey).getPrivateKeyData(), null, passPhrase); } catch (JSchException e) { throw new SSHException("The " + Constants.PRIVATE_KEY_DATA + " is invalid.", e); } } } }
public static void setIdentity(JSch jsch, IdentityKey identityKey) throws SSHException { byte[] passPhrase = identityKey.getPassPhrase(); if (identityKey instanceof KeyFile) { try { jsch.addIdentity(((KeyFile) identityKey).getKeyFilePath(), passPhrase); } catch (JSchException e) { throw new SSHException("The keyFilePath is invalid.", e); } } else { try { jsch.addIdentity(((KeyData) identityKey).getKeyName(), ((KeyData) identityKey).getPrivateKeyData(), null, passPhrase); } catch (JSchException e) { throw new SSHException("The " + Constants.PRIVATE_KEY_DATA + " is invalid.", e); } } } }