Ejemplo n.º 1
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
    }
  }