Esempio n. 1
0
 public synchronized boolean add(byte[] identity) {
   try {
     Identity _identity = IdentityFile.newInstance("from remote:", identity, null, jsch);
     add(_identity);
     return true;
   } catch (JSchException e) {
     return false;
   }
 }
Esempio n. 2
0
  /**
   * Sets the private key, which will be referred in the public key authentication. Before
   * registering it into identityRepository, it will be deciphered with <code>passphrase</code>.
   *
   * @param identity private key.
   * @param passphrase passphrase for <code>identity</code>.
   * @throws JSchException if <code>passphrase</code> is not right.
   */
  public void addIdentity(Identity identity, byte[] passphrase) throws JSchException {
    if (passphrase != null) {
      try {
        byte[] goo = new byte[passphrase.length];
        System.arraycopy(passphrase, 0, goo, 0, passphrase.length);
        passphrase = goo;
        identity.setPassphrase(passphrase);
      } finally {
        Util.bzero(passphrase);
      }
    }

    if (identityRepository instanceof LocalIdentityRepository) {
      ((LocalIdentityRepository) identityRepository).add(identity);
    } else {
      // TODO
    }
  }